diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2022-11-17 15:57:11 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2022-11-18 08:31:56 -0800 |
commit | 10788166e7e568fdcd0b748e8d5dab442dcdc7ef (patch) | |
tree | ee195186a3fed8333bc1875f66ddab0c85c3d7db /gc.c | |
parent | f0ce1186620273a1182e6084559765143099eb88 (diff) | |
download | ruby-10788166e7e568fdcd0b748e8d5dab442dcdc7ef.tar.gz |
Differentiate T_OBJECT shapes from other objects
We would like to differentiate types of objects via their shape. This
commit adds a special T_OBJECT shape when we allocate an instance of
T_OBJECT. This allows us to avoid testing whether an object is an
instance of a T_OBJECT or not, we can just check the shape.
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -2942,6 +2942,12 @@ rb_class_instance_allocate_internal(VALUE klass, VALUE flags, bool wb_protected) #endif VALUE obj = newobj_of(klass, flags, 0, 0, 0, wb_protected, size); + RUBY_ASSERT(rb_shape_get_shape(obj)->type == SHAPE_ROOT || + rb_shape_get_shape(obj)->type == SHAPE_INITIAL_CAPACITY); + + // Set the shape to the specific T_OBJECT shape which is always + // SIZE_POOL_COUNT away from the root shape. + ROBJECT_SET_SHAPE_ID(obj, ROBJECT_SHAPE_ID(obj) + SIZE_POOL_COUNT); #if RUBY_DEBUG VALUE *ptr = ROBJECT_IVPTR(obj); @@ -10030,7 +10036,7 @@ gc_ref_update_object(rb_objspace_t *objspace, VALUE v) } ptr = ROBJECT(v)->as.ary; size_t size_pool_shape_id = size_pool_idx_for_size(embed_size); - rb_shape_t * initial_shape = rb_shape_get_shape_by_id((shape_id_t)size_pool_shape_id); + rb_shape_t * initial_shape = rb_shape_get_shape_by_id((shape_id_t)size_pool_shape_id + SIZE_POOL_COUNT); rb_shape_t * new_shape = rb_shape_rebuild_shape(initial_shape, rb_shape_get_shape(v)); rb_shape_set_shape(v, new_shape); } |