提交 17b9f68f authored 作者: Anthony Minessale's avatar Anthony Minessale

add better tolower to go with the toupper

上级 30e4c71b
......@@ -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);
......
......@@ -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);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论