]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: regex: PCRE2 use JIT match when JIT optimisation occured.
authorDavid Carlier <devnexen@gmail.com>
Thu, 13 Aug 2020 13:53:41 +0000 (14:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Aug 2020 05:53:40 +0000 (07:53 +0200)
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>
include/haproxy/regex-t.h
include/haproxy/regex.h
src/regex.c

index f265994301013df181fb94cc50893113f3855b52..ff415e8e165c1749860eedaf7c421a296da5879a 100644 (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;
index e093051a6d5083fc2eba2bbcc3baf1b7cced7301..2cd9573e9b639bcd4d356215794b54f64aec35c8 100644 (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)
index 95da30353487b0cddd09948da8034ca6f36bf105..45a7e9004e8e4f6ad9604ed9a858aba0060b6204 100644 (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