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.
This commit is contained in:
parent
86e3d63772
commit
3a3728e4b3
Notes:
git
2020-06-29 11:07:14 +09:00
29
class.c
29
class.c
@ -1778,26 +1778,25 @@ singleton_class_of(VALUE obj)
|
|||||||
{
|
{
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
|
|
||||||
if (FIXNUM_P(obj) || FLONUM_P(obj) || STATIC_SYM_P(obj)) {
|
switch (TYPE(obj)) {
|
||||||
no_singleton:
|
case T_FIXNUM:
|
||||||
|
case T_BIGNUM:
|
||||||
|
case T_FLOAT:
|
||||||
|
case T_SYMBOL:
|
||||||
rb_raise(rb_eTypeError, "can't define singleton");
|
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);
|
klass = special_singleton_class_of(obj);
|
||||||
if (NIL_P(klass))
|
if (NIL_P(klass))
|
||||||
rb_bug("unknown immediate %p", (void *)obj);
|
rb_bug("unknown immediate %p", (void *)obj);
|
||||||
return klass;
|
return klass;
|
||||||
}
|
|
||||||
else {
|
case T_STRING:
|
||||||
switch (BUILTIN_TYPE(obj)) {
|
if (FL_TEST_RAW(obj, RSTRING_FSTR)) {
|
||||||
case T_FLOAT: case T_BIGNUM: case T_SYMBOL:
|
rb_raise(rb_eTypeError, "can't define singleton");
|
||||||
goto no_singleton;
|
}
|
||||||
case T_STRING:
|
|
||||||
if (FL_TEST_RAW(obj, RSTRING_FSTR)) goto no_singleton;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
klass = RBASIC(obj)->klass;
|
klass = RBASIC(obj)->klass;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user