Fixup hot paths - add macro for toupper (c < 0x80).
authorJeremy Allison <jra@samba.org>
Thu, 10 Jan 2008 01:32:26 +0000 (17:32 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 10 Jan 2008 01:32:26 +0000 (17:32 -0800)
This now matches 3.0.x on my micro-tests.
Jeremy.
(This used to be commit 329b924cba8225002ca40db26c45b31d141a0925)

source3/include/smb_macros.h
source3/lib/charcnv.c
source3/lib/util_str.c

index 3324f3fc02de6891fe6a7559c4153af266cefe80..463a2bdb0b8fc578f9cd3fad80471cb1a5f61ce6 100644 (file)
@@ -385,4 +385,12 @@ do { \
 #define ISDOTDOT(p) (*(p) == '.' && *((p) + 1) == '.' && *((p) + 2) == '\0')
 #endif /* ISDOTDOT */
 
+#ifndef toupper_ascii_fast
+/* Warning - this must only be called with 0 <= c < 128. IT WILL
+ * GIVE GARBAGE if c > 128 or c < 0. JRA.
+ */
+extern char toupper_ascii_fast_table[];
+#define toupper_ascii_fast(c) toupper_ascii_fast_table[(unsigned int)(c)];
+#endif
+
 #endif /* _SMB_MACROS_H */
index 8a00b235ccc10c99eac953afed06d22ee47ff666..eeff80545905587e530adf431cb96be000c81c73 100644 (file)
@@ -614,10 +614,16 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
   out:
 
        destlen = destlen - o_len;
-       if (ctx) {
-               ob = (char *)TALLOC_REALLOC(ctx,ob,destlen);
-       } else {
-               ob = (char *)SMB_REALLOC(ob,destlen);
+       /* Don't shrink unless we're reclaiming a lot of
+        * space. This is in the hot codepath and these
+        * reallocs *cost*. JRA.
+        */
+       if (o_len > 1024) {
+               if (ctx) {
+                       ob = (char *)TALLOC_REALLOC(ctx,ob,destlen);
+               } else {
+                       ob = (char *)SMB_REALLOC(ob,destlen);
+               }
        }
 
        if (destlen && !ob) {
@@ -778,7 +784,7 @@ char *strdup_upper(const char *s)
        while (*p) {
                if (*p & 0x80)
                        break;
-               *q++ = toupper_ascii(*p);
+               *q++ = toupper_ascii_fast(*p);
                p++;
        }
 
@@ -844,7 +850,7 @@ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s)
        while (*p) {
                if (*p & 0x80)
                        break;
-               *q++ = toupper_ascii(*p);
+               *q++ = toupper_ascii_fast(*p);
                p++;
        }
 
index 7e21fe11953c43e37114f0454d079ba19282cecd..3e3268104c0458822bef39d546203f628565018b 100644 (file)
 
 #include "includes.h"
 
+char toupper_ascii_fast_table[128] = {
+       0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
+       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+       0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+       0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+       0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+       0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+       0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+       0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f
+};
+
 /**
  * @file
  * @brief String utilities.
@@ -187,8 +198,8 @@ int StrCaseCmp(const char *s, const char *t)
                         * from here on in */
                        break;
 
-               us = toupper_ascii(*ps);
-               ut = toupper_ascii(*pt);
+               us = toupper_ascii_fast(*ps);
+               ut = toupper_ascii_fast(*pt);
                if (us == ut)
                        continue;
                else if (us < ut)
@@ -246,8 +257,8 @@ int StrnCaseCmp(const char *s, const char *t, size_t len)
                         * hard way from here on in */
                        break;
 
-               us = toupper_ascii(*ps);
-               ut = toupper_ascii(*pt);
+               us = toupper_ascii_fast(*ps);
+               ut = toupper_ascii_fast(*pt);
                if (us == ut)
                        continue;
                else if (us < ut)
@@ -1679,7 +1690,7 @@ void strupper_m(char *s)
           (ie. they match for the first 128 chars) */
 
        while (*s && !(((unsigned char)s[0]) & 0x80)) {
-               *s = toupper_ascii((unsigned char)*s);
+               *s = toupper_ascii_fast((unsigned char)*s);
                s++;
        }