From 3a3728e4b37b422dae617ed75520e28426835053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Thu, 11 Jun 2020 13:53:16 +0900 Subject: singleton_class_of: 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. --- class.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/class.c b/class.c index 47bb56230f..8ac53ee63b 100644 --- a/class.c +++ b/class.c @@ -1778,26 +1778,25 @@ singleton_class_of(VALUE obj) { VALUE klass; - if (FIXNUM_P(obj) || FLONUM_P(obj) || STATIC_SYM_P(obj)) { - no_singleton: + switch (TYPE(obj)) { + case T_FIXNUM: + case T_BIGNUM: + case T_FLOAT: + case T_SYMBOL: rb_raise(rb_eTypeError, "can't define singleton"); - } - if (SPECIAL_CONST_P(obj)) { + + case T_FALSE: + case T_TRUE: + case T_NIL: klass = special_singleton_class_of(obj); if (NIL_P(klass)) rb_bug("unknown immediate %p", (void *)obj); return klass; - } - else { - switch (BUILTIN_TYPE(obj)) { - case T_FLOAT: case T_BIGNUM: case T_SYMBOL: - goto no_singleton; - case T_STRING: - if (FL_TEST_RAW(obj, RSTRING_FSTR)) goto no_singleton; - break; - default: - break; - } + + case T_STRING: + if (FL_TEST_RAW(obj, RSTRING_FSTR)) { + rb_raise(rb_eTypeError, "can't define singleton"); + } } klass = RBASIC(obj)->klass; -- cgit v1.2.1