OPTIM: regex: PCRE2 use JIT match when JIT optimisation occured.

When a regex had been succesfully compiled by the JIT pass, it is better
 to use the related match, thanksfully having same signature, for better
 performance.

Signed-off-by: David Carlier <devnexen@gmail.com>
This commit is contained in:
David Carlier 2020-08-13 14:53:41 +01:00 committed by Willy Tarreau
parent 935d8294d5
commit 7adf8f35df
3 changed files with 9 additions and 5 deletions

View File

@ -54,6 +54,7 @@ struct my_regex {
#endif
#endif
#elif USE_PCRE2
int(*mfn)(const pcre2_code *, PCRE2_SPTR, PCRE2_SIZE, PCRE2_SIZE, uint32_t, pcre2_match_data *, pcre2_match_context *);
pcre2_code *reg;
#else /* no PCRE */
regex_t regex;

View File

@ -62,7 +62,7 @@ static inline int regex_exec(const struct my_regex *preg, char *subject)
int ret;
pm = pcre2_match_data_create_from_pattern(preg->reg, NULL);
ret = pcre2_match(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)strlen(subject),
ret = preg->mfn(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)strlen(subject),
0, 0, pm, NULL);
pcre2_match_data_free(pm);
if (ret < 0)
@ -94,7 +94,7 @@ static inline int regex_exec2(const struct my_regex *preg, char *subject, int le
int ret;
pm = pcre2_match_data_create_from_pattern(preg->reg, NULL);
ret = pcre2_match(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)length,
ret = preg->mfn(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)length,
0, 0, pm, NULL);
pcre2_match_data_free(pm);
if (ret < 0)

View File

@ -170,7 +170,7 @@ int regex_exec_match(const struct my_regex *preg, const char *subject,
*/
#ifdef USE_PCRE2
pm = pcre2_match_data_create_from_pattern(preg->reg, NULL);
ret = pcre2_match(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)strlen(subject), 0, options, pm, NULL);
ret = preg->mfn(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)strlen(subject), 0, options, pm, NULL);
if (ret < 0) {
pcre2_match_data_free(pm);
@ -252,7 +252,7 @@ int regex_exec_match2(const struct my_regex *preg, char *subject, int length,
options |= PCRE_NOTBOL;
#endif
/* The value returned by pcre_exec()/pcre2_match() is one more than the highest numbered
/* The value returned by pcre_exec()/pcre2_(jit)_match() is one more than the highest numbered
* pair that has been set. For example, if two substrings have been captured,
* the returned value is 3. If there are no capturing subpatterns, the return
* value from a successful match is 1, indicating that just the first pair of
@ -263,7 +263,7 @@ int regex_exec_match2(const struct my_regex *preg, char *subject, int length,
*/
#ifdef USE_PCRE2
pm = pcre2_match_data_create_from_pattern(preg->reg, NULL);
ret = pcre2_match(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)length, 0, options, pm, NULL);
ret = preg->mfn(preg->reg, (PCRE2_SPTR)subject, (PCRE2_SIZE)length, 0, options, pm, NULL);
if (ret < 0) {
pcre2_match_data_free(pm);
@ -365,6 +365,7 @@ struct my_regex *regex_comp(const char *str, int cs, int cap, char **err)
goto out_fail_alloc;
}
regex->mfn = &pcre2_match;
#if defined(USE_PCRE2_JIT)
jit = pcre2_jit_compile(regex->reg, PCRE2_JIT_COMPLETE);
/*
@ -375,6 +376,8 @@ struct my_regex *regex_comp(const char *str, int cs, int cap, char **err)
pcre2_code_free(regex->reg);
memprintf(err, "regex '%s' jit compilation failed", str);
goto out_fail_alloc;
} else {
regex->mfn = &pcre2_jit_match;
}
#endif