Skip to content

Commit 2021146

Browse files
committed
Use RB_BUILTIN_TYPE in RCLASS_SINGLETON_P
This should avoid us emitting the check for a special constant.
1 parent 3e851ea commit 2021146

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,7 @@ rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
26302630
int recur = TRUE;
26312631

26322632
if (rb_check_arity(argc, 0, 1)) recur = RTEST(argv[0]);
2633-
if (RCLASS_SINGLETON_P(obj)) {
2633+
if (RB_TYPE_P(obj, T_CLASS) && RCLASS_SINGLETON_P(obj)) {
26342634
rb_singleton_class(obj);
26352635
}
26362636
klass = CLASS_OF(obj);

internal/class.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ RUBY_SYMBOL_EXPORT_END
491491
static inline bool
492492
RCLASS_SINGLETON_P(VALUE klass)
493493
{
494-
return RB_TYPE_P(klass, T_CLASS) && FL_TEST_RAW(klass, FL_SINGLETON);
494+
RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS));
495+
return RB_BUILTIN_TYPE(klass) == T_CLASS && FL_TEST_RAW(klass, FL_SINGLETON);
495496
}
496497

497498
static inline void

0 commit comments

Comments
 (0)