rb_str_subpat_set: do not goto into a branch

I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
This commit is contained in:
卜部昌平 2020-06-18 13:18:12 +09:00
parent 0358846f8c
commit 841eea4bcb
Notes: git 2020-06-29 11:06:47 +09:00

View File

@ -4772,14 +4772,10 @@ rb_str_subpat_set(VALUE str, VALUE re, VALUE backref, VALUE val)
match = rb_backref_get();
nth = rb_reg_backref_number(match, backref);
regs = RMATCH_REGS(match);
if (nth >= regs->num_regs) {
out_of_range:
if ((nth >= regs->num_regs) || ((nth < 0) && (-nth >= regs->num_regs))) {
rb_raise(rb_eIndexError, "index %d out of regexp", nth);
}
if (nth < 0) {
if (-nth >= regs->num_regs) {
goto out_of_range;
}
nth += regs->num_regs;
}