diff options
author | HParker <HParker@github.com> | 2023-02-17 08:15:03 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2023-03-09 15:34:49 -0800 |
commit | 69465df4242f3b2d8e55fbe18d7c45b47b40a626 (patch) | |
tree | 57aad5e76cfff0615df51443ede9b010d1c4f2f4 /shape.c | |
parent | 65a95b82593683ba2e566fe1d14b086b80874c92 (diff) | |
download | ruby-69465df4242f3b2d8e55fbe18d7c45b47b40a626.tar.gz |
Allow classes and modules to become too complex
This makes the behavior of classes and modules when there are too many instance variables match the behavior of objects with too many instance variables.
Diffstat (limited to 'shape.c')
-rw-r--r-- | shape.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -239,7 +239,7 @@ remove_shape_recursive(VALUE obj, ID id, rb_shape_t * shape, VALUE * removed) if (new_parent) { bool dont_care; enum ruby_value_type type = BUILTIN_TYPE(obj); - bool new_shape_necessary = type != T_OBJECT; + bool new_shape_necessary = type != T_OBJECT && type != T_CLASS && type != T_MODULE; rb_shape_t * new_child = get_next_shape_internal(new_parent, shape->edge_name, shape->type, &dont_care, true, new_shape_necessary); new_child->capacity = shape->capacity; if (new_child->type == SHAPE_IVAR) { @@ -316,12 +316,10 @@ rb_shape_get_next(rb_shape_t* shape, VALUE obj, ID id) } bool variation_created = false; - // For non T_OBJECTS, force a new shape - bool new_shape_necessary = BUILTIN_TYPE(obj) != T_OBJECT; + bool new_shape_necessary = BUILTIN_TYPE(obj) != T_OBJECT && BUILTIN_TYPE(obj) != T_CLASS && BUILTIN_TYPE(obj) != T_MODULE; rb_shape_t * new_shape = get_next_shape_internal(shape, id, SHAPE_IVAR, &variation_created, allow_new_shape, new_shape_necessary); if (!new_shape) { - RUBY_ASSERT(BUILTIN_TYPE(obj) == T_OBJECT); new_shape = rb_shape_get_shape_by_id(OBJ_TOO_COMPLEX_SHAPE_ID); } @@ -336,6 +334,15 @@ rb_shape_get_next(rb_shape_t* shape, VALUE obj, ID id) RCLASS_EXT(klass)->variation_count++; } } + else if (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE) { + if (new_shape->next_iv_index > RCLASS_EXT(obj)->max_iv_count) { + RCLASS_EXT(obj)->max_iv_count = new_shape->next_iv_index; + } + + if (variation_created) { + RCLASS_EXT(obj)->variation_count++; + } + } return new_shape; } @@ -523,7 +530,6 @@ rb_shape_obj_too_complex(VALUE obj) void rb_shape_set_too_complex(VALUE obj) { - RUBY_ASSERT(BUILTIN_TYPE(obj) == T_OBJECT); RUBY_ASSERT(!rb_shape_obj_too_complex(obj)); rb_shape_set_shape_id(obj, OBJ_TOO_COMPLEX_SHAPE_ID); } |