summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2022-03-04 23:31:37 -0800
committerJohn Hawthorn <john@hawthorn.email>2022-03-17 11:48:39 -0700
commit29b68b89a0c0ea7de46c058fab746550398151f0 (patch)
tree9f6167fa5e2198bf9d65026c395c118bd37d04d2
parent58b355175c13b5795a3119bbdc48b8ab8c31b6b4 (diff)
downloadruby-29b68b89a0c0ea7de46c058fab746550398151f0.tar.gz
Faster rb_class_superclass
This uses the RCLASS_SUPERCLASSES array to quickly find the next SUPERCLASS of klass which is a T_CLASS.
-rw-r--r--object.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/object.c b/object.c
index f6736fbe8b..26eb823621 100644
--- a/object.c
+++ b/object.c
@@ -2034,19 +2034,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