diff options
author | John Hawthorn <[email protected]> | 2022-02-26 16:05:06 -0800 |
---|---|---|
committer | John Hawthorn <[email protected]> | 2022-03-03 11:23:27 -0800 |
commit | 19f331f58823dc0ff90ba7806c46380dc4064fa3 (patch) | |
tree | 230da9fe95b90dc396f20acf4c8c79850aeebf6a /internal/class.h | |
parent | 4d28009f09f0554467d914acb3c4c2dcf1cebfe7 (diff) |
Dedup superclass array in leaf sibling classes
Previously, we would build a new `superclasses` array for each class,
even though for all immediate subclasses of a class, the array is
identical.
This avoids duplicating the arrays on leaf classes (those without
subclasses) by calculating and storing a "superclasses including self"
array on a class when it's first inherited and sharing that among all
superclasses.
An additional trick used is that the "superclass array including self"
is valid as "self"'s superclass array. It just has it's own class at the
end. We can use this to avoid an extra pointer of storage and can use
one bit of a flag to track that we've "upgraded" the array.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5604
Diffstat (limited to 'internal/class.h')
-rw-r--r-- | internal/class.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/internal/class.h b/internal/class.h index c6151299c7..be2f703fc8 100644 --- a/internal/class.h +++ b/internal/class.h @@ -124,13 +124,14 @@ typedef struct rb_classext_struct rb_classext_t; #define RICLASS_IS_ORIGIN FL_USER5 #define RCLASS_CLONED FL_USER6 +#define RCLASS_SUPERCLASSES_INCLUDE_SELF FL_USER7 #define RICLASS_ORIGIN_SHARED_MTBL FL_USER8 /* class.c */ void rb_class_subclass_add(VALUE super, VALUE klass); void rb_class_remove_from_super_subclasses(VALUE); void rb_class_update_superclasses(VALUE); -void rb_class_remove_superclasses(VALUE); +size_t rb_class_superclasses_memsize(VALUE); void rb_class_remove_subclass_head(VALUE); int rb_singleton_class_internal_p(VALUE sklass); VALUE rb_class_boot(VALUE); |