diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2021-03-14 08:09:58 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-03-22 07:10:32 -0400 |
commit | 7b9c5adda1f8254119627973618c4157746abba9 (patch) | |
tree | 206362c9726f5bee5b97f4c4eafe145263f82ae2 /src/keyvalue.c | |
parent | 8845e1e67ee1d5acb277a10095e803a9f2012a42 (diff) | |
download | lighttpd-git-7b9c5adda1f8254119627973618c4157746abba9.tar.gz |
[multiple] PCRE w/ PCRE_STUDY_JIT_COMPILE (fixes #2361)
enabled by default
disable using server.feature-flags += ("server.pcre_jit" => "disable")
Available since pcre-8.20 (2011), and improved in pcre-8.32 (2012),
PCRE_STUDY_JIT_COMPILE can greatly speed up repeated execution of PCRE
patterns. (https://zherczeg.github.io/sljit/pcre.html)
lighttpd continues to use pcre_exec() instead of pcre_jit_exec(),
even though doing so does not realize all of the performance increase
potentially available with PCRE_STUDY_JIT_COMPILE and pcre_jit_exec().
pcre_jit_exec() is available with PCRE 8.32 and later, if PCRE is
compiled with --enable-jit, but lighttpd does not currently use
pcre_jit_exec() since the PCRE library might not have been compiled
with --enable-jit (though this could be solved with a weak symbol).
Similarly, lighttpd does not currently configure the pcre_jit_stack.
(Using pcre_jit_exec() may be revisited in the future.)
x-ref:
"add support for pcre JIT"
https://redmine.lighttpd.net/issues/2361
Diffstat (limited to 'src/keyvalue.c')
-rw-r--r-- | src/keyvalue.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/keyvalue.c b/src/keyvalue.c index 2adde419..8aa21844 100644 --- a/src/keyvalue.c +++ b/src/keyvalue.c @@ -17,6 +17,10 @@ #ifdef HAVE_PCRE_H #include <pcre.h> +#ifndef PCRE_STUDY_JIT_COMPILE +#define PCRE_STUDY_JIT_COMPILE 0 +#define pcre_free_study(x) pcre_free(x) +#endif #endif typedef struct pcre_keyvalue { @@ -36,7 +40,7 @@ pcre_keyvalue_buffer *pcre_keyvalue_buffer_init(void) { return kvb; } -int pcre_keyvalue_buffer_append(log_error_st *errh, pcre_keyvalue_buffer *kvb, const buffer *key, const buffer *value) { +int pcre_keyvalue_buffer_append(log_error_st *errh, pcre_keyvalue_buffer *kvb, const buffer *key, const buffer *value, const int pcre_jit) { #ifdef HAVE_PCRE_H const char *errptr; int erroff; @@ -62,8 +66,12 @@ int pcre_keyvalue_buffer_append(log_error_st *errh, pcre_keyvalue_buffer *kvb, c return 0; } - if (NULL == (kv->key_extra = pcre_study(kv->key, 0, &errptr)) && - errptr != NULL) { + const int study_options = pcre_jit ? PCRE_STUDY_JIT_COMPILE : 0; + if (NULL == (kv->key_extra = pcre_study(kv->key, study_options, &errptr)) + && errptr != NULL) { + log_error(errh, __FILE__, __LINE__, + "studying regex failed: %s -> %s\n", + key->ptr, errptr); return 0; } #else @@ -75,6 +83,7 @@ int pcre_keyvalue_buffer_append(log_error_st *errh, pcre_keyvalue_buffer *kvb, c UNUSED(kvb); UNUSED(key); UNUSED(value); + UNUSED(pcre_jit); #endif return 1; @@ -85,7 +94,7 @@ void pcre_keyvalue_buffer_free(pcre_keyvalue_buffer *kvb) { for (uint32_t i = 0; i < kvb->used; ++i) { pcre_keyvalue * const kv = kvb->kv+i; if (kv->key) pcre_free(kv->key); - if (kv->key_extra) pcre_free(kv->key_extra); + if (kv->key_extra) pcre_free_study(kv->key_extra); /*free (kv->value.ptr);*//*(see pcre_keyvalue_buffer_append)*/ } |