feat: PCRE2 JIT

This commit is contained in:
wfjsw
2022-08-25 02:38:05 +08:00
parent 7b094ea84e
commit 0d81b636be
4 changed files with 55 additions and 9 deletions

View File

@@ -36,6 +36,8 @@ namespace operators {
VerifyCC::~VerifyCC() {
#if WITH_PCRE2
pcre2_code_free(m_pc);
pcre2_match_context_free(m_pmc);
pcre2_jit_stack_free(m_pcjs);
#else
if (m_pc != NULL) {
pcre_free(m_pc);
@@ -105,6 +107,11 @@ bool VerifyCC::init(const std::string &param2, std::string *error) {
if (m_pc == NULL) {
return false;
}
m_pcje = pcre2_jit_compile(m_pc, PCRE2_JIT_COMPLETE);
m_pmc = pcre2_match_context_create(NULL);
m_pcjs = pcre2_jit_stack_create(32*1024, 512*1024, NULL);
pcre2_jit_stack_assign(m_pmc, NULL, m_pcjs);
#else
const char *errptr = NULL;
int erroffset = 0;
@@ -142,8 +149,14 @@ bool VerifyCC::evaluate(Transaction *t, RuleWithActions *rule,
PCRE2_SPTR pcre2_i = reinterpret_cast<PCRE2_SPTR>(i.c_str());
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(m_pc, NULL);
int ret;
for (offset = 0; offset < target_length; offset++) {
int ret = pcre2_match(m_pc, pcre2_i, target_length, offset, 0, match_data, NULL);
if (m_pcje == 0) {
ret = pcre2_jit_match(m_pc, pcre2_i, target_length, offset, 0, match_data, m_pmc);
} else {
ret = pcre2_match(m_pc, pcre2_i, target_length, offset, 0, match_data, m_pmc);
}
/* If there was no match, then we are done. */
if (ret < 0) {

View File

@@ -53,6 +53,9 @@ class VerifyCC : public Operator {
private:
#if WITH_PCRE2
pcre2_code *m_pc;
pcre2_match_context *m_pmc;
int m_pcje;
pcre2_jit_stack *m_pcjs;
#else
pcre *m_pc;
pcre_extra *m_pce;