1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Faster rb_class_superclass

This uses the RCLASS_SUPERCLASSES array to quickly find the next
SUPERCLASS of klass which is a T_CLASS.
This commit is contained in:
John Hawthorn 2022-03-04 23:31:37 -08:00
parent 87fb0864bd
commit a8541475d1
Notes: git 2022-04-27 06:09:20 +09:00

View file

@ -2038,20 +2038,19 @@ rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
VALUE VALUE
rb_class_superclass(VALUE klass) rb_class_superclass(VALUE klass)
{ {
RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
VALUE super = RCLASS_SUPER(klass); VALUE super = RCLASS_SUPER(klass);
if (!super) { if (!super) {
if (klass == rb_cBasicObject) return Qnil; if (klass == rb_cBasicObject) return Qnil;
rb_raise(rb_eTypeError, "uninitialized class"); rb_raise(rb_eTypeError, "uninitialized class");
} } else {
while (RB_TYPE_P(super, T_ICLASS)) { super = RCLASS_SUPERCLASSES(klass)[RCLASS_SUPERCLASS_DEPTH(klass) - 1];
super = RCLASS_SUPER(super); RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
}
if (!super) {
return Qnil;
}
return super; return super;
} }
}
VALUE VALUE
rb_class_get_superclass(VALUE klass) rb_class_get_superclass(VALUE klass)