]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-4928 doing 100 calls I found 7 million calls to toupper, this patch replaces it...
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 12 Dec 2012 01:18:25 +0000 (19:18 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 12 Dec 2012 01:18:25 +0000 (19:18 -0600)
src/include/switch_utils.h
src/switch_utils.c

index c9e2c189c862998ac1e4c9732932e1a0fc8dd608..92618a81d505a607d5677472eff61827357e27ec 100644 (file)
 
 #include <switch.h>
 
-SWITCH_BEGIN_EXTERN_C SWITCH_DECLARE(int) switch_toupper(int c);
+SWITCH_BEGIN_EXTERN_C 
+
+/* https://code.google.com/p/stringencoders/wiki/PerformanceAscii */
+static inline uint32_t switch_toupper(uint32_t eax)
+{
+    uint32_t ebx = (0x7f7f7f7ful & eax) + 0x05050505ul;
+    ebx = (0x7f7f7f7ful & ebx) + 0x1a1a1a1aul;
+    ebx = ((ebx & ~eax) >> 2 ) & 0x20202020ul;
+    return eax - ebx;
+}
+
+SWITCH_DECLARE(int) old_switch_toupper(int c);
 SWITCH_DECLARE(int) switch_tolower(int c);
 SWITCH_DECLARE(int) switch_isalnum(int c);
 SWITCH_DECLARE(int) switch_isalpha(int c);
index 4335b4dcd399d7801ca6907151245d1c539230d6..83b77744a37eda3d3ab7d1e22e28873b7101fec5 100644 (file)
@@ -2609,7 +2609,7 @@ const short _switch_C_toupper_[1 + SWITCH_CTYPE_NUM_CHARS] = {
 
 const short *_switch_toupper_tab_ = _switch_C_toupper_;
 
-SWITCH_DECLARE(int) switch_toupper(int c)
+SWITCH_DECLARE(int) old_switch_toupper(int c)
 {
        if ((unsigned int) c > 255)
                return (c);