diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2020-09-10 00:15:29 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2020-10-11 12:19:26 -0400 |
commit | c58b95f2976a0563884a09a6aafb5e1332e3ca3b (patch) | |
tree | 2262699f6c12134fc7e7bf76db1a21ceb7903815 /src/buffer.c | |
parent | 327de98b38d84921e342422f34848a4f85a4da9c (diff) | |
download | lighttpd-git-c58b95f2976a0563884a09a6aafb5e1332e3ca3b.tar.gz |
[core] light_isupper(), light_islower()
more efficient char checks
(replace one comparision and one branch with one subtraction)
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/buffer.c b/src/buffer.c index b3b90454..d10b4b21 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -327,9 +327,9 @@ int buffer_eq_icase_ssn(const char * const a, const char * const b, const size_t if (ca != cb) { ca |= 0x20; cb |= 0x20; - if (ca != cb) return 0; - if (ca < 'a' || 'z' < ca) return 0; - if (cb < 'a' || 'z' < cb) return 0; + if (ca != cb) return 0; + if (!light_islower(ca)) return 0; + if (!light_islower(cb)) return 0; } } return 1; @@ -921,19 +921,17 @@ void buffer_path_simplify(buffer *dest, buffer *src) } void buffer_to_lower(buffer * const b) { - char * const s = b->ptr; + unsigned char * const restrict s = (unsigned char *)b->ptr; for (uint32_t i = 0; i < b->used; ++i) { - char c = s[i]; - if (c >= 'A' && c <= 'Z') s[i] |= 0x20; + if (light_isupper(s[i])) s[i] |= 0x20; } } void buffer_to_upper(buffer * const b) { - char * const s = b->ptr; + unsigned char * const restrict s = (unsigned char *)b->ptr; for (uint32_t i = 0; i < b->used; ++i) { - char c = s[i]; - if (c >= 'a' && c <= 'z') s[i] &= ~0x20; + if (light_islower(s[i])) s[i] &= 0xdf; } } |