aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-16 12:18:51 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit3db159193ed86b6db409e00ac73adab143283b4e (patch)
treed981e71e47181aaca27ff4c4b7cd8963ca360f37 /proc.c
parent8b9b51bb3ba246590e528702285f5f5e92271b50 (diff)
downloadruby-3db159193ed86b6db409e00ac73adab143283b4e.tar.gz
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.
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/proc.c b/proc.c
index 3ebd8d4535..ee4ca9a368 100644
--- a/proc.c
+++ b/proc.c
@@ -1989,27 +1989,38 @@ rb_obj_public_method(VALUE obj, VALUE vid)
VALUE
rb_obj_singleton_method(VALUE obj, VALUE vid)
{
- const rb_method_entry_t *me;
VALUE klass = rb_singleton_class_get(obj);
ID id = rb_check_id(&vid);
- if (NIL_P(klass) || NIL_P(klass = RCLASS_ORIGIN(klass))) {
- undef:
- rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
- obj, vid);
+ if (NIL_P(klass)) {
+ /* goto undef; */
}
- 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);
if (m) return m;
- goto undef;
+ /* else goto undef; */
}
- me = rb_method_entry_at(klass, id);
- if (UNDEFINED_METHOD_ENTRY_P(me) ||
- UNDEFINED_REFINED_METHOD_P(me->def)) {
- vid = ID2SYM(id);
- goto undef;
+ else {
+ const rb_method_entry_t *me = rb_method_entry_at(klass, id);
+ vid = ID2SYM(id);
+
+ 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);
}
/*