Skip to content

Commit

Permalink
Allow the match cache optimization for atomic groups (#7804)
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed May 22, 2023
1 parent 872249e commit a5819b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions regexec.c
Expand Up @@ -446,8 +446,10 @@ count_num_cache_opcodes(const regex_t* reg, long* num_cache_opcodes_ptr)
case OP_POP_POS:
case OP_PUSH_POS_NOT:
case OP_FAIL_POS:
goto impossible;
case OP_PUSH_STOP_BT:
case OP_POP_STOP_BT:
break;
case OP_LOOK_BEHIND:
case OP_PUSH_LOOK_BEHIND_NOT:
case OP_FAIL_LOOK_BEHIND_NOT:
Expand Down Expand Up @@ -709,8 +711,10 @@ init_cache_opcodes(const regex_t* reg, OnigCacheOpcode* cache_opcodes, long* num
case OP_POP_POS:
case OP_PUSH_POS_NOT:
case OP_FAIL_POS:
goto unexpected_bytecode_error;
case OP_PUSH_STOP_BT:
case OP_POP_STOP_BT:
break;
case OP_LOOK_BEHIND:
case OP_PUSH_LOOK_BEHIND_NOT:
case OP_FAIL_LOOK_BEHIND_NOT:
Expand Down
10 changes: 10 additions & 0 deletions test/ruby/test_regexp.rb
Expand Up @@ -1760,6 +1760,16 @@ def test_match_cache_square
end;
end

def test_match_cache_atomic
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
timeout = #{ EnvUtil.apply_timeout_scale(10).inspect }
begin;
Regexp.timeout = timeout
assert_nil(/^(?>a?a?)(a|a)*$/ =~ "a" * 1000000 + "x")
end;
end

def test_cache_opcodes_initialize
str = 'test1-test2-test3-test4-test_5'
re = '^([0-9a-zA-Z\-/]*){1,256}$'
Expand Down

0 comments on commit a5819b5

Please sign in to comment.