aboutsummaryrefslogtreecommitdiffstats
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-11-03 08:53:50 -0400
committerPeter Zhu <peter@peterzhu.ca>2023-11-03 10:15:32 -0400
commit1321df773b6316d2e88dfcada7844e00762d5a94 (patch)
tree85c38ca7ea7676b4bc47a3287ae8411084621865 /vm_insnhelper.c
parentec86b2eb3947060cffbc95c7c236e110a269c7de (diff)
downloadruby-1321df773b6316d2e88dfcada7844e00762d5a94.tar.gz
Use shape capacity transitions for generic ivars
This commit changes generic ivars to respect the capacity transition in shapes rather than growing the capacity independently.
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 785dbfedec..bea80ed588 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1458,21 +1458,13 @@ vm_setivar_default(VALUE obj, ID id, VALUE val, shape_id_t dest_shape_id, attr_i
// Cache hit case
if (shape_id == dest_shape_id) {
RUBY_ASSERT(dest_shape_id != INVALID_SHAPE_ID && shape_id != INVALID_SHAPE_ID);
-
- // Just get the IV table
- rb_gen_ivtbl_get(obj, 0, &ivtbl);
}
else if (dest_shape_id != INVALID_SHAPE_ID) {
- rb_shape_t * dest_shape = rb_shape_get_shape_by_id(dest_shape_id);
- shape_id_t source_shape_id = dest_shape->parent_id;
+ rb_shape_t *dest_shape = rb_shape_get_shape_by_id(dest_shape_id);
- if (shape_id == source_shape_id && dest_shape->edge_name == id && dest_shape->type == SHAPE_IVAR) {
- ivtbl = rb_ensure_generic_iv_list_size(obj, dest_shape, index + 1);
-#if SHAPE_IN_BASIC_FLAGS
- RBASIC_SET_SHAPE_ID(obj, dest_shape_id);
-#else
- RUBY_ASSERT(ivtbl->shape_id == dest_shape_id);
-#endif
+ if (shape_id == dest_shape->parent_id && dest_shape->edge_name == id && dest_shape->type == SHAPE_IVAR) {
+ RUBY_ASSERT(rb_shape_get_shape_by_id(shape_id)->capacity == dest_shape->capacity);
+ RUBY_ASSERT(index < rb_shape_get_shape_by_id(shape_id)->capacity);
}
else {
return Qundef;
@@ -1482,9 +1474,17 @@ vm_setivar_default(VALUE obj, ID id, VALUE val, shape_id_t dest_shape_id, attr_i
return Qundef;
}
- VALUE *ptr = ivtbl->as.shape.ivptr;
+ rb_gen_ivtbl_get(obj, 0, &ivtbl);
+
+ if (shape_id != dest_shape_id) {
+#if SHAPE_IN_BASIC_FLAGS
+ RBASIC_SET_SHAPE_ID(obj, dest_shape_id);
+#else
+ ivtbl->shape_id = dest_shape_id;
+#endif
+ }
- RB_OBJ_WRITE(obj, &ptr[index], val);
+ RB_OBJ_WRITE(obj, &ivtbl->as.shape.ivptr[index], val);
RB_DEBUG_COUNTER_INC(ivar_set_ic_hit);