]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add better tolower to go with the toupper
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 8 Jan 2013 20:21:41 +0000 (14:21 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 8 Jan 2013 20:21:41 +0000 (14:21 -0600)
src/include/switch_utils.h
src/switch_utils.c

index 4705069728737418e522b4f1fbdbc5aaee7ecbfa..485d7c3495b2e05934ffc740e8ac2dff785231bd 100644 (file)
@@ -42,7 +42,9 @@
 
 SWITCH_BEGIN_EXTERN_C 
 
-/* https://code.google.com/p/stringencoders/wiki/PerformanceAscii */
+/* https://code.google.com/p/stringencoders/wiki/PerformanceAscii 
+   http://www.azillionmonkeys.com/qed/asmexample.html
+*/
 static inline uint32_t switch_toupper(uint32_t eax)
 {
        uint32_t ebx = (0x7f7f7f7ful & eax) + 0x05050505ul;
@@ -51,6 +53,17 @@ static inline uint32_t switch_toupper(uint32_t eax)
        return eax - ebx;
 }
 
+/* https://code.google.com/p/stringencoders/wiki/PerformanceAscii 
+   http://www.azillionmonkeys.com/qed/asmexample.html
+*/
+static inline uint32_t switch_tolower(uint32_t eax)
+{
+       uint32_t ebx = (0x7f7f7f7ful & eax) + 0x25252525ul;
+       ebx = (0x7f7f7f7ful & ebx) + 0x1a1a1a1aul;
+       ebx = ((ebx & ~eax) >> 2)  & 0x20202020ul;
+       return eax + ebx;
+}
+
 #ifdef FS_64BIT
 
 static inline void switch_toupper_max(char *s)
@@ -81,6 +94,34 @@ static inline void switch_toupper_max(char *s)
 
 }
 
+static inline void switch_tolower_max(char *s)
+{
+       uint64_t *b,*p;
+       char *c;
+       size_t l;
+
+       l = strlen(s);
+
+       p = (uint64_t *) s;
+
+       while (l > 8) {
+               b = p;
+               *b = (uint32_t) switch_tolower(*b);
+               b++;
+               p++;
+               l -= 8;
+       }
+
+       c = (char *)p;
+
+       while(l > 0) {
+               *c = (char) switch_tolower(*c);
+               c++;
+               l--;
+       }
+
+}
+
 #else 
 
 static inline void switch_toupper_max(char *s)
@@ -109,12 +150,40 @@ static inline void switch_toupper_max(char *s)
                l--;
        }
        
+}
+
+static inline void switch_tolower_max(char *s)
+{
+       uint32_t *b,*p;
+       char *c;
+       size_t l;
+
+       l = strlen(s);
+
+       p = (uint32_t *) s;
+
+       while (l > 4) {
+               b = p;
+               *b = (uint32_t) switch_tolower(*b);
+               b++;
+               p++;
+               l -= 4;
+       }
+
+       c = (char *)p;
+
+       while(l > 0) {
+               *c = (char) switch_tolower(*c);
+               c++;
+               l--;
+       }
+       
 }
 #endif
 
 
 SWITCH_DECLARE(int) old_switch_toupper(int c);
-SWITCH_DECLARE(int) switch_tolower(int c);
+SWITCH_DECLARE(int) old_switch_tolower(int c);
 SWITCH_DECLARE(int) switch_isalnum(int c);
 SWITCH_DECLARE(int) switch_isalpha(int c);
 SWITCH_DECLARE(int) switch_iscntrl(int c);
index 83b77744a37eda3d3ab7d1e22e28873b7101fec5..3051f156cf7e79285147cd39e2435edbb9d6284f 100644 (file)
@@ -2656,7 +2656,7 @@ const short _switch_C_tolower_[1 + SWITCH_CTYPE_NUM_CHARS] = {
 
 const short *_switch_tolower_tab_ = _switch_C_tolower_;
 
-SWITCH_DECLARE(int) switch_tolower(int c)
+SWITCH_DECLARE(int) old_switch_tolower(int c)
 {
        if ((unsigned int) c > 255)
                return (c);