Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/iscsi Don't pre-compute string sizes in a relatively...



details:   https://anonhg.NetBSD.org/src/rev/167c5bda10dd
branches:  trunk
changeset: 808383:167c5bda10dd
user:      joerg <joerg%NetBSD.org@localhost>
date:      Fri May 15 18:28:36 2015 +0000

description:
Don't pre-compute string sizes in a relatively cold function.

diffstat:

 sys/dev/iscsi/iscsi_main.c |  36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diffs (62 lines):

diff -r 9e141724d2bf -r 167c5bda10dd sys/dev/iscsi/iscsi_main.c
--- a/sys/dev/iscsi/iscsi_main.c        Fri May 15 18:03:45 2015 +0000
+++ b/sys/dev/iscsi/iscsi_main.c        Fri May 15 18:28:36 2015 +0000
@@ -228,28 +228,19 @@
 
 typedef struct quirktab_t {
        const char      *tgt;
-       size_t           tgtlen;
        const char      *iqn;
-       size_t           iqnlen;
        uint32_t         quirks;
 } quirktab_t;
 
 static const quirktab_t        quirktab[] = {
-       { "StarWind",   8,
-               "iqn.2008-08.com.starwindsoftware",     32,
-               PQUIRK_ONLYBIG  },
-       { "UNH",        3,
-               "iqn.2002-10.edu.unh.", 20,
-               PQUIRK_NOBIGMODESENSE |
-               PQUIRK_NOMODESENSE |
-               PQUIRK_NOSYNCCACHE },
-       { "NetBSD",     6,
-               "iqn.1994-04.org.netbsd.",      23,
-               0       },
-       { "Unknown",    7,
-               "unknown",      7,
-               0       },
-       { NULL,         0,      NULL,   0,      0       }
+       { "StarWind", "iqn.2008-08.com.starwindsoftware", PQUIRK_ONLYBIG },
+       { "UNH", "iqn.2002-10.edu.unh.",
+           PQUIRK_NOBIGMODESENSE |
+           PQUIRK_NOMODESENSE |
+           PQUIRK_NOSYNCCACHE },
+       { "NetBSD", "iqn.1994-04.org.netbsd.", 0 },
+       { "Unknown", "unknown", 0 },
+       { NULL, NULL, 0 }
 };
 
 /* loop through the quirktab looking for a match on target name */
@@ -257,14 +248,17 @@
 getquirks(const char *iqn)
 {
        const quirktab_t        *qp;
+       size_t iqnlen, quirklen;
 
-       if (iqn == NULL) {
+       if (iqn == NULL)
                iqn = "unknown";
-       }
+       iqnlen = strlen(iqn);
        for (qp = quirktab ; qp->iqn ; qp++) {
-               if (strncmp(qp->iqn, iqn, qp->iqnlen) == 0) {
+               quirklen = strlen(qp->iqn);
+               if (quirklen > iqnlen)
+                       continue;
+               if (memcmp(qp->iqn, iqn, quirklen) == 0)
                        break;
-               }
        }
        return qp;
 }



Home | Main Index | Thread Index | Old Index