summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-06-04 21:16:58 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2019-06-06 02:48:43 -0400
commitca059d580d590a5d4931e58de5b8d0ce2f540781 (patch)
tree86ac5fa3de5887e7c733c9df896e4c9b2e5ef3aa
parent4fb5a791b08f4817cca93564d435e6624b4edb74 (diff)
downloadlighttpd1.4-ca059d580d590a5d4931e58de5b8d0ce2f540781.tar.gz
lighttpd1.4-ca059d580d590a5d4931e58de5b8d0ce2f540781.zip
[core] array-specialized buffer_caseless_compare()
specialize buffer_caseless_compare() for array.c
-rw-r--r--src/array.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/array.c b/src/array.c
index 1b54ec5c..a317951d 100644
--- a/src/array.c
+++ b/src/array.c
@@ -99,8 +99,26 @@ data_unset *array_pop(array *a) {
return du;
}
+__attribute_pure__
+static int array_caseless_compare(const char * const a, const char * const b, const size_t len) {
+ for (size_t i = 0; i < len; ++i) {
+ unsigned int ca = ((unsigned char *)a)[i];
+ unsigned int cb = ((unsigned char *)b)[i];
+ if (ca == cb) continue;
+
+ /* always lowercase for transitive results */
+ if (ca >= 'A' && ca <= 'Z') ca |= 32;
+ if (cb >= 'A' && cb <= 'Z') cb |= 32;
+
+ if (ca == cb) continue;
+ return (int)(ca - cb);
+ }
+ return 0;
+}
+
+__attribute_pure__
static int array_keycmp(const char *a, size_t alen, const char *b, size_t blen) {
- return alen < blen ? -1 : alen > blen ? 1 : buffer_caseless_compare(a, alen, b, blen);
+ return alen < blen ? -1 : alen > blen ? 1 : array_caseless_compare(a, b, blen);
}
/* returns index of element or ARRAY_NOT_FOUND