MEDIUM: regex: Use PCRE JIT in acl
This is a patch for using PCRE JIT in acl.
I notice regex are used in other places, but they are more complicated
to modify to use PCRE APIs. So I focused to acl in the first try.
BTW, I made a simple benchmark program for PCRE JIT beforehand.
https://github.com/hnakamur/pcre-jit-benchmark
I read the manual for PCRE JIT
http://www.manpagez.com/man/3/pcrejit/
and wrote my benchmark program.
https://github.com/hnakamur/pcre-jit-benchmark/blob/master/test-pcre.c
diff --git a/include/common/regex.h b/include/common/regex.h
index 60c7f42..bab1a55 100644
--- a/include/common/regex.h
+++ b/include/common/regex.h
@@ -27,8 +27,20 @@
#ifdef USE_PCRE
#include <pcre.h>
#include <pcreposix.h>
-#else
+
+#ifdef USE_PCRE_JIT
+struct jit_regex {
+ pcre *reg;
+ pcre_extra *extra;
+};
+typedef struct jit_regex regex;
+#else /* no PCRE_JIT */
+typedef regex_t regex;
+#endif
+
+#else /* no PCRE */
#include <regex.h>
+typedef regex_t regex;
#endif
/* what to do when a header matches a regex */
@@ -55,6 +67,24 @@
const char *chain_regex(struct hdr_exp **head, const regex_t *preg,
int action, const char *replace, void *cond);
+static inline int regex_exec(const regex *preg, const char *subject, int length) {
+#ifdef USE_PCRE_JIT
+ return pcre_exec(preg->reg, preg->extra, subject, length, 0, 0, NULL, 0);
+#else
+ return regexec(preg, subject, 0, NULL, 0);
+#endif
+}
+
+static inline void regex_free(regex *preg) {
+#ifdef USE_PCRE_JIT
+ pcre_free_study(preg->extra);
+ pcre_free(preg->reg);
+ free(preg);
+#else
+ regfree(preg);
+#endif
+}
+
#endif /* _COMMON_REGEX_H */
/*