Skip to content

Commit

Permalink
Reuse the backref if it isn't marked as busy.
Browse files Browse the repository at this point in the history
[Misc #20652]
  • Loading branch information
byroot committed Feb 24, 2025
1 parent 87f9c3c commit 97e6ad4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions re.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,11 +1813,20 @@ rb_reg_search_set_match(VALUE re, VALUE str, long pos, int reverse, int set_back
return ONIG_MISMATCH;
}

VALUE match;
if (set_match && RTEST(*set_match)) {
VALUE match = Qnil;
if (set_match) {
match = *set_match;
}
else {

if (NIL_P(match)) {
match = rb_backref_get();
}

if (!NIL_P(match) && FL_TEST(match, MATCH_BUSY)) {
match = Qnil;
}

if (NIL_P(match)) {
match = match_alloc(rb_cMatch);
}

Expand Down

0 comments on commit 97e6ad4

Please sign in to comment.