diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-11 13:53:16 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-29 11:05:41 +0900 |
commit | 3a3728e4b37b422dae617ed75520e28426835053 (patch) | |
tree | f33258f9e0196d2475a4977ee0c7d55363a09603 | |
parent | 86e3d63772533d6b301ab0d9e73b719c47d96f7f (diff) | |
download | ruby-3a3728e4b37b422dae617ed75520e28426835053.tar.gz |
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.
-rw-r--r-- | class.c | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -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; |