summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-11 13:53:16 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit3a3728e4b37b422dae617ed75520e28426835053 (patch)
treef33258f9e0196d2475a4977ee0c7d55363a09603 /class.c
parent86e3d63772533d6b301ab0d9e73b719c47d96f7f (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'class.c')
-rw-r--r--class.c29
1 files 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;