summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-11-15 10:52:39 -0500
committerPeter Zhu <peter@peterzhu.ca>2022-11-21 09:58:53 -0500
commit648927d71bde5df02a0490f5f45bb7fcde913376 (patch)
treecb89cd7440e51d374e3e6346e1a0d72514532a3c /vm_insnhelper.c
parent612aa5c24a7c249867bbcd7d6567012aa6a7f4b9 (diff)
downloadruby-648927d71bde5df02a0490f5f45bb7fcde913376.tar.gz
Refactor obj_ivar_set and vm_setivar
obj_ivar_set and vm_setivar_slowpath is essentially doing the same thing, but the code is duplicated and not quite implemented in the same way, which could cause bugs. This commit refactors vm_setivar_slowpath to use obj_ivar_set.
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c28
1 files changed, 1 insertions, 27 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 5d7d5ddee8..76bdbb86de 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1299,38 +1299,12 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic,
{
rb_check_frozen_internal(obj);
- attr_index_t index;
+ attr_index_t index = rb_obj_ivar_set(obj, id, val);
- rb_shape_t* shape = rb_shape_get_shape(obj);
- uint32_t num_iv = shape->capacity;
shape_id_t next_shape_id = ROBJECT_SHAPE_ID(obj);
- if (!rb_shape_get_iv_index(shape, id, &index)) {
- if (UNLIKELY(shape->next_iv_index >= num_iv)) {
- RUBY_ASSERT(shape->next_iv_index == num_iv);
-
- shape = rb_grow_iv_list(obj);
- RUBY_ASSERT(shape->type == SHAPE_CAPACITY_CHANGE);
- }
-
- index = shape->next_iv_index;
-
- if (index >= MAX_IVARS) {
- rb_raise(rb_eArgError, "too many instance variables");
- }
-
- rb_shape_t * next_shape = rb_shape_get_next(shape, obj, id);
- RUBY_ASSERT(next_shape->type == SHAPE_IVAR);
- RUBY_ASSERT(index == (next_shape->next_iv_index - 1));
- next_shape_id = rb_shape_id(next_shape);
-
- rb_shape_set_shape(obj, next_shape);
- }
-
populate_cache(index, next_shape_id, id, iseq, ic, cc, is_attr);
- VALUE *ptr = ROBJECT_IVPTR(obj);
- RB_OBJ_WRITE(obj, &ptr[index], val);
RB_DEBUG_COUNTER_INC(ivar_set_ic_miss_iv_hit);
return val;
}