rb_obj_singleton_method: 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-16 12:18:51 +09:00
parent 8b9b51bb3b
commit 3db159193e
Notes: git 2020-06-29 11:06:55 +09:00

37
proc.c
View File

@ -1989,27 +1989,38 @@ rb_obj_public_method(VALUE obj, VALUE vid)
VALUE VALUE
rb_obj_singleton_method(VALUE obj, VALUE vid) rb_obj_singleton_method(VALUE obj, VALUE vid)
{ {
const rb_method_entry_t *me;
VALUE klass = rb_singleton_class_get(obj); VALUE klass = rb_singleton_class_get(obj);
ID id = rb_check_id(&vid); ID id = rb_check_id(&vid);
if (NIL_P(klass) || NIL_P(klass = RCLASS_ORIGIN(klass))) { if (NIL_P(klass)) {
undef: /* goto undef; */
rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
obj, vid);
} }
if (!id) { else if (NIL_P(klass = RCLASS_ORIGIN(klass))) {
/* goto undef; */
}
else if (! id) {
VALUE m = mnew_missing_by_name(klass, obj, &vid, FALSE, rb_cMethod); VALUE m = mnew_missing_by_name(klass, obj, &vid, FALSE, rb_cMethod);
if (m) return m; if (m) return m;
goto undef; /* else goto undef; */
} }
me = rb_method_entry_at(klass, id); else {
if (UNDEFINED_METHOD_ENTRY_P(me) || const rb_method_entry_t *me = rb_method_entry_at(klass, id);
UNDEFINED_REFINED_METHOD_P(me->def)) { vid = ID2SYM(id);
vid = ID2SYM(id);
goto undef; if (UNDEFINED_METHOD_ENTRY_P(me)) {
/* goto undef; */
}
else if (UNDEFINED_REFINED_METHOD_P(me->def)) {
/* goto undef; */
}
else {
return mnew_from_me(me, klass, klass, obj, id, rb_cMethod, FALSE);
}
} }
return mnew_from_me(me, klass, klass, obj, id, rb_cMethod, FALSE);
/* undef: */
rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
obj, vid);
} }
/* /*