rb_str_rindex_m: 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:
parent
c29ec1ef1a
commit
c422fc4bbc
Notes:
git
2020-06-29 11:06:49 +09:00
23
string.c
23
string.c
@ -3821,9 +3821,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
|||||||
pos = len;
|
pos = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SPECIAL_CONST_P(sub)) goto generic;
|
if (RB_TYPE_P(sub, T_REGEXP)) {
|
||||||
switch (BUILTIN_TYPE(sub)) {
|
|
||||||
case T_REGEXP:
|
|
||||||
/* enc = rb_get_check(str, sub); */
|
/* enc = rb_get_check(str, sub); */
|
||||||
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
|
pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
|
||||||
enc, single_byte_optimizable(str));
|
enc, single_byte_optimizable(str));
|
||||||
@ -3831,24 +3829,11 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
|
|||||||
pos = rb_reg_search(sub, str, pos, 1);
|
pos = rb_reg_search(sub, str, pos, 1);
|
||||||
pos = rb_str_sublen(str, pos);
|
pos = rb_str_sublen(str, pos);
|
||||||
if (pos >= 0) return LONG2NUM(pos);
|
if (pos >= 0) return LONG2NUM(pos);
|
||||||
break;
|
}
|
||||||
|
else {
|
||||||
generic:
|
StringValue(sub);
|
||||||
default: {
|
|
||||||
VALUE tmp;
|
|
||||||
|
|
||||||
tmp = rb_check_string_type(sub);
|
|
||||||
if (NIL_P(tmp)) {
|
|
||||||
rb_raise(rb_eTypeError, "type mismatch: %s given",
|
|
||||||
rb_obj_classname(sub));
|
|
||||||
}
|
|
||||||
sub = tmp;
|
|
||||||
}
|
|
||||||
/* fall through */
|
|
||||||
case T_STRING:
|
|
||||||
pos = rb_str_rindex(str, sub, pos);
|
pos = rb_str_rindex(str, sub, pos);
|
||||||
if (pos >= 0) return LONG2NUM(pos);
|
if (pos >= 0) return LONG2NUM(pos);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user