On Tue, 29 Sep 2009 08:11:37 -0700 (PDT) bugzilla-daemon at np.grommit.com 
wrote:
> Note that the changes to usr/src/lib/libsum/common/sumlib.c have the same
> performance benefit than using the hardcoded table in
> usr/src/lib/libsum/common/sum-crc.c.
> It seems the usage of |sfsprintf()|+|strmatch()| is _very_ expensive in this
> codepath... ;-/

here is a patch for a simple method name prefix match

--- .../sumlib.c        Fri May  2 11:05:51 2008
+++ sumlib.c    Tue Sep 29 11:46:55 2009
@@ -6,7 +6,7 @@
  * man this is sum library
  */
 
-static const char id[] = "\n@(#)$Id: sumlib (AT&T Research) 2008-05-01 $\0\n";
+static const char id[] = "\n@(#)$Id: sumlib (AT&T Research) 2009-09-28 $\0\n";
 
 #define _SUM_PRIVATE_  \
                        struct Method_s*        method; \
@@ -214,6 +214,40 @@
 };
 
 /*
+ * simple alternation prefix match
+ */
+
+static int
+match(register const char* s, register const char* p)
+{
+       register const char*    b = s;
+
+       for (;;)
+       {
+               do
+               {
+                       if (*p == '|' || *p == 0)
+                               return 1;
+               } while (*s++ == *p++);
+               for (;;)
+               {
+                       switch (*p++)
+                       {
+                       case 0:
+                               return 0;
+                       case '|':
+                               break;
+                       default:
+                               continue;
+                       }
+                       break;
+               }
+               s = b;
+       }
+       return 0;
+}
+
+/*
  * open sum method name
  */
 
@@ -226,20 +260,14 @@
        if (!name || !name[0] || name[0] == '-' && !name[1])
                name = "default";
        for (n = 0; n < elementsof(maps); n++)
-       {
-               sfsprintf(pat, sizeof(pat), "*@(%s)*", maps[n].match);
-               if (strmatch(name, pat))
+               if (match(name, maps[n].match))
                {
                        name = maps[n].map;
                        break;
                }
-       }
        for (n = 0; n < elementsof(methods); n++)
-       {
-               sfsprintf(pat, sizeof(pat), "*@(%s)*", methods[n].match);
-               if (strmatch(name, pat))
+               if (match(name, methods[n].match))
                        return (*methods[n].open)(&methods[n], name);
-       }
        return 0;
 }
 

Reply via email to