diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2021-11-20 03:29:38 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2021-11-20 03:33:16 -0500 |
commit | 6d47d4c69997c3f62e35d71203d770a4a98dcb56 (patch) | |
tree | 78c32d5bb94ce6cf10d33691d79063daa30caa0b /src/configfile-glue.c | |
parent | 3b3574c5e6d57aeeebe87706bb861762d1a3826f (diff) | |
download | lighttpd-git-6d47d4c69997c3f62e35d71203d770a4a98dcb56.tar.gz |
[core] use stack w/ pcre_exec unless save captures
use stack w/ pcre_exec unless saving captures from config conditions
reduce memory allocations per request where lighttpd.conf does not
contain url.redirect or url.rewrite rules where replacements reference
a match of the enclosing lighttpd.conf condition (e.g. %0, %1, %2 ...)
move cond_cache_t 'patterncount' to cond_match_t 'captures'
While cond_match_t is no longer sized power-2, it is generally expected
to be used much less frequently than before (which was all the time),
since it is now used only with url.redirect or url.rewrite with
references %0, %1, %2, ...
Diffstat (limited to 'src/configfile-glue.c')
-rw-r--r-- | src/configfile-glue.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/configfile-glue.c b/src/configfile-glue.c index cb100bcd..9e2de5bf 100644 --- a/src/configfile-glue.c +++ b/src/configfile-glue.c @@ -642,19 +642,22 @@ void config_cond_cache_reset(request_st * const r) { static int config_pcre_match(request_st * const r, const data_config * const dc, const buffer * const b) { #ifdef HAVE_PCRE_H + if (__builtin_expect( (0 == dc->capture_idx), 1)) { + int matches[3 * 10]; + return pcre_exec(dc->regex, dc->regex_study, BUF_PTR_LEN(b), 0, 0, + matches, sizeof(matches)/sizeof(*matches)); + } + #ifndef elementsof #define elementsof(x) (sizeof(x) / sizeof(x[0])) #endif cond_match_t * const cond_match = r->cond_match[dc->capture_idx] = r->cond_match_data + dc->capture_idx; cond_match->comp_value = b; /*holds pointer to b (!) for pattern subst*/ - /* Note: patterncount is in cond_cache_t instead of cond_match_t only - * so that both structures are sized power-2 for efficient array access */ - cond_cache_t * const cache = &r->cond_cache[dc->context_ndx]; - cache->patterncount = + cond_match->captures = pcre_exec(dc->regex, dc->regex_study, BUF_PTR_LEN(b), 0, 0, cond_match->matches, elementsof(cond_match->matches)); - return cache->patterncount; + return cond_match->captures; #else UNUSED(r); UNUSED(dc); |