summaryrefslogtreecommitdiff
path: root/src/mod_alias.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2019-10-15 22:45:30 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2020-05-23 17:59:29 -0400
commite3dc34d142b43db5b3245b5e62024b507a09641d (patch)
tree3fc082efb91f79ba3a8deeb35c6b08b4ad3db38b /src/mod_alias.c
parenta762402da55033a10b01f38272da445df50b7c01 (diff)
downloadlighttpd-git-e3dc34d142b43db5b3245b5e62024b507a09641d.tar.gz
[core] array a->sorted[] as ptrs rather than pos
While slightly more memory use in 64-bit (though same memory use as prior versions of lighttpd), avoids bouncing through second array when searching in sorted list. Most use of arrays in lighttpd is to build a list once, and elements are not removed from the list.
Diffstat (limited to 'src/mod_alias.c')
-rw-r--r--src/mod_alias.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/mod_alias.c b/src/mod_alias.c
index 7b817be4..55b591ca 100644
--- a/src/mod_alias.c
+++ b/src/mod_alias.c
@@ -99,9 +99,9 @@ SETDEFAULTS_FUNC(mod_alias_set_defaults) {
size_t j, k;
for (j = 0; j < a->used; j ++) {
- const buffer *prefix = &a->data[a->sorted[j]]->key;
+ const buffer *prefix = &a->sorted[j]->key;
for (k = j + 1; k < a->used; k ++) {
- const buffer *key = &a->data[a->sorted[k]]->key;
+ const buffer *key = &a->sorted[k]->key;
if (buffer_string_length(key) < buffer_string_length(prefix)) {
break;
@@ -110,7 +110,11 @@ SETDEFAULTS_FUNC(mod_alias_set_defaults) {
break;
}
/* ok, they have same prefix. check position */
- if (a->sorted[j] < a->sorted[k]) {
+ const data_unset *dj = a->sorted[j];
+ const data_unset *dk = a->sorted[k];
+ const data_unset **data = (const data_unset **)a->data;
+ while (*data != dj && *data != dk) ++data;
+ if (*data == dj) {
log_error_write(srv, __FILE__, __LINE__, "SBSBS",
"url.alias: `", key, "' will never match as `", prefix, "' matched first");
return HANDLER_ERROR;