Optimize regexp matching for look-around and atomic groups (#7931)

This commit is contained in:
Hiroya Fujinami 2023-10-30 13:10:42 +09:00 committed by GitHub
parent 13c9cbe09e
commit 34cb174800
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 306 additions and 157 deletions

View file

@ -1273,6 +1273,10 @@ compile_length_enclose_node(EncloseNode* node, regex_t* reg)
break;
case ENCLOSE_STOP_BACKTRACK:
/* Disable POP_STOP_BT optimization for simple repeat under the match cache */
/* optimization because the match cache optimization pushes an extra item to */
/* the stack and it breaks the assumption for this optimization. */
#ifndef USE_MATCH_CACHE
if (IS_ENCLOSE_STOP_BT_SIMPLE_REPEAT(node)) {
QtfrNode* qn = NQTFR(node->target);
tlen = compile_length_tree(qn->target, reg);
@ -1282,8 +1286,11 @@ compile_length_enclose_node(EncloseNode* node, regex_t* reg)
+ SIZE_OP_PUSH + tlen + SIZE_OP_POP + SIZE_OP_JUMP;
}
else {
#endif
len = SIZE_OP_PUSH_STOP_BT + tlen + SIZE_OP_POP_STOP_BT;
#ifndef USE_MATCH_CACHE
}
#endif
break;
case ENCLOSE_CONDITION:
@ -1395,6 +1402,10 @@ compile_enclose_node(EncloseNode* node, regex_t* reg)
break;
case ENCLOSE_STOP_BACKTRACK:
/* Disable POP_STOP_BT optimization for simple repeat under the match cache */
/* optimization because the match cache optimization pushes an extra item to */
/* the stack and it breaks the assumption for this optimization. */
#ifndef USE_MATCH_CACHE
if (IS_ENCLOSE_STOP_BT_SIMPLE_REPEAT(node)) {
QtfrNode* qn = NQTFR(node->target);
r = compile_tree_n_times(qn->target, qn->lower, reg);
@ -1413,12 +1424,15 @@ compile_enclose_node(EncloseNode* node, regex_t* reg)
-((int )SIZE_OP_PUSH + len + (int )SIZE_OP_POP + (int )SIZE_OP_JUMP));
}
else {
#endif
r = add_opcode(reg, OP_PUSH_STOP_BT);
if (r) return r;
r = compile_tree(node->target, reg);
if (r) return r;
r = add_opcode(reg, OP_POP_STOP_BT);
#ifndef USE_MATCH_CACHE
}
#endif
break;
case ENCLOSE_CONDITION: