summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2025-05-20 13:10:41 -0700
committerJohn Hawthorn <john@hawthorn.email>2025-05-23 10:22:24 -0700
commit11ad7f5f47b4e4919bcf7a03338a62ef5b5396cc (patch)
tree24b162eff4ed9bdf6c846cb85319e0f99b5c5125 /gc.c
parent1435ea7f44f3d781a03054b4055a1ad2f90dd392 (diff)
Don't use namespaced classext for superclasses
Superclasses can't be modified by user code, so do not need namespace indirection. For example Object.superclass is always BasicObject, no matter what modules are included onto it.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13420
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/gc.c b/gc.c
index 199e6b9788..aba799ab25 100644
--- a/gc.c
+++ b/gc.c
@@ -1238,7 +1238,8 @@ classext_free(rb_classext_t *ext, bool is_prime, VALUE namespace, void *arg)
rb_id_table_free(tbl);
}
rb_class_classext_free_subclasses(ext, args->klass);
- if (RCLASSEXT_SUPERCLASSES_OWNER(ext)) {
+ if (RCLASSEXT_SUPERCLASSES_WITH_SELF(ext)) {
+ RUBY_ASSERT(is_prime); // superclasses should only be used on prime
xfree(RCLASSEXT_SUPERCLASSES(ext));
}
if (!is_prime) { // the prime classext will be freed with RClass
@@ -2293,10 +2294,9 @@ classext_superclasses_memsize(rb_classext_t *ext, bool prime, VALUE namespace, v
{
size_t *size = (size_t *)arg;
size_t array_size;
- if (RCLASSEXT_SUPERCLASSES_OWNER(ext)) {
- array_size = RCLASSEXT_SUPERCLASS_DEPTH(ext);
- if (RCLASSEXT_SUPERCLASSES_WITH_SELF(ext))
- array_size += 1;
+ if (RCLASSEXT_SUPERCLASSES_WITH_SELF(ext)) {
+ RUBY_ASSERT(prime);
+ array_size = RCLASSEXT_SUPERCLASS_DEPTH(ext) + 1;
*size += array_size * sizeof(VALUE);
}
}
@@ -3802,10 +3802,8 @@ update_subclasses(void *objspace, rb_classext_t *ext)
static void
update_superclasses(rb_objspace_t *objspace, rb_classext_t *ext)
{
- size_t array_size = RCLASSEXT_SUPERCLASS_DEPTH(ext);
- if (RCLASSEXT_SUPERCLASSES_OWNER(ext)) {
- if (RCLASSEXT_SUPERCLASSES_WITH_SELF(ext))
- array_size += 1;
+ if (RCLASSEXT_SUPERCLASSES_WITH_SELF(ext)) {
+ size_t array_size = RCLASSEXT_SUPERCLASS_DEPTH(ext) + 1;
for (size_t i = 0; i < array_size; i++) {
UPDATE_IF_MOVED(objspace, RCLASSEXT_SUPERCLASSES(ext)[i]);
}