summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2022-03-04 23:31:37 -0800
committerJohn Hawthorn <john@hawthorn.email>2022-04-26 14:08:55 -0700
commita8541475d1339ce242357822dd49d775645ce76d (patch)
treee687bdf0d98527bdf0580f81c9c0f370577245e5 /object.c
parent87fb0864bd2e4618d237bcbcf4ade1c4098d96e3 (diff)
Faster rb_class_superclass
This uses the RCLASS_SUPERCLASSES array to quickly find the next SUPERCLASS of klass which is a T_CLASS.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5850
Diffstat (limited to 'object.c')
-rw-r--r--object.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/object.c b/object.c
index eaf30e0dff..47ccedc4f7 100644
--- a/object.c
+++ b/object.c
@@ -2038,19 +2038,18 @@ rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
VALUE
rb_class_superclass(VALUE klass)
{
+ RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
+
VALUE super = RCLASS_SUPER(klass);
if (!super) {
if (klass == rb_cBasicObject) return Qnil;
rb_raise(rb_eTypeError, "uninitialized class");
+ } else {
+ super = RCLASS_SUPERCLASSES(klass)[RCLASS_SUPERCLASS_DEPTH(klass) - 1];
+ RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
+ return super;
}
- while (RB_TYPE_P(super, T_ICLASS)) {
- super = RCLASS_SUPER(super);
- }
- if (!super) {
- return Qnil;
- }
- return super;
}
VALUE