diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-09-10 13:41:38 -0700 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:40 -0400 |
commit | 5bc0343261cc420d08fb8462ba9ad616c7596b1d (patch) | |
tree | 9ffc06f26a99002ec0449a4593637fdcb64ba484 /vm_insnhelper.c | |
parent | 5092d6129a9f1d57752a29f4808fe74e1c6a666b (diff) |
Refactor attrset to use a function
This new function will do the write barrier / resize the object / check
frozen for us
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 802305ff01..772850a728 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1371,6 +1371,24 @@ rb_vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, VALUE val, IV vm_setinstancevariable(iseq, obj, id, val, ic); } +VALUE +rb_vm_set_ivar_idx(VALUE obj, uint32_t index, VALUE val) +{ + RUBY_ASSERT(RB_TYPE_P(obj, T_OBJECT)); + + rb_check_frozen_internal(obj); + + VM_ASSERT(!rb_ractor_shareable_p(obj)); + + if (UNLIKELY(index >= ROBJECT_NUMIV(obj))) { + rb_init_iv_list(obj); + } + VALUE *ptr = ROBJECT_IVPTR(obj); + RB_OBJ_WRITE(obj, &ptr[index], val); + RB_DEBUG_COUNTER_INC(ivar_set_ic_hit); + return val; /* inline cache hit */ +} + static VALUE vm_throw_continue(const rb_execution_context_t *ec, VALUE err) { |