rb_str_match: 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-17 16:05:43 +09:00
parent c422fc4bbc
commit d49924ed81
Notes: git 2020-06-29 11:06:48 +09:00

View File

@ -3864,15 +3864,13 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
static VALUE static VALUE
rb_str_match(VALUE x, VALUE y) rb_str_match(VALUE x, VALUE y)
{ {
if (SPECIAL_CONST_P(y)) goto generic; switch (OBJ_BUILTIN_TYPE(y)) {
switch (BUILTIN_TYPE(y)) {
case T_STRING: case T_STRING:
rb_raise(rb_eTypeError, "type mismatch: String given"); rb_raise(rb_eTypeError, "type mismatch: String given");
case T_REGEXP: case T_REGEXP:
return rb_reg_match(y, x); return rb_reg_match(y, x);
generic:
default: default:
return rb_funcall(y, idEqTilde, 1, x); return rb_funcall(y, idEqTilde, 1, x);
} }