Fix to work match cache with peek next optimization (#9459)

This commit is contained in:
Hiroya Fujinami 2024-01-10 11:22:23 +09:00 committed by GitHub
parent 1817d644ee
commit 597955aae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -3758,14 +3758,15 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
CASE(OP_PUSH_IF_PEEK_NEXT) MOP_IN(OP_PUSH_IF_PEEK_NEXT);
GET_RELADDR_INC(addr, p);
CHECK_MATCH_CACHE;
if (*p == *s) {
p++;
CHECK_MATCH_CACHE;
STACK_PUSH_ALT(p + addr, s, sprev, pkeep);
MOP_OUT;
JUMP;
}
p++;
INC_NUM_FAILS;
MOP_OUT;
JUMP;

View File

@ -1945,6 +1945,15 @@ class TestRegexp < Test::Unit::TestCase
end;
end
def test_match_cache_with_peek_optimization
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
timeout = #{ EnvUtil.apply_timeout_scale(10).inspect }
begin;
Regexp.timeout = timeout
assert_nil(/a*z/ =~ "a" * 1000000 + "x")
end;
end
def test_cache_opcodes_initialize
str = 'test1-test2-test3-test4-test_5'
re = '^([0-9a-zA-Z\-/]*){1,256}$'