aboutsummaryrefslogtreecommitdiffstats
path: root/regcomp.c
diff options
context:
space:
mode:
authorHiroya Fujinami <make.just.on@gmail.com>2023-10-30 13:10:42 +0900
committerGitHub <noreply@github.com>2023-10-30 13:10:42 +0900
commit34cb174800e1e41323807c99386641b688927adc (patch)
tree62a1ac23fa566aff85a18042655bebbd2bd750ab /regcomp.c
parent13c9cbe09ef310c7ddf055d57ebf4586e9f9a111 (diff)
downloadruby-34cb174800e1e41323807c99386641b688927adc.tar.gz
Optimize regexp matching for look-around and atomic groups (#7931)
Diffstat (limited to 'regcomp.c')
-rw-r--r--regcomp.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/regcomp.c b/regcomp.c
index b880c85bf1..0b29b27034 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -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: