diff options
author | Aaron Patterson <[email protected]> | 2020-11-09 11:20:29 -0800 |
---|---|---|
committer | Aaron Patterson <[email protected]> | 2020-11-09 14:05:41 -0800 |
commit | f259906eabac6038bb7c79e426c17ae850c8e017 (patch) | |
tree | 37fb06596e81816d3d5dab5bf5e3a84d4f88c042 /vm_insnhelper.c | |
parent | 6778ba48fddcab1bca56b9bccc7ea5f9583baba8 (diff) |
Avoid slow path ivar setting
If the ivar index table exists, we can avoid the slowest path for
setting ivars.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3750
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 398bbd741e..ea25de629f 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1237,6 +1237,17 @@ vm_setivar(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, const str else { vm_cc_attr_index_set(cc, (int)(ent->index + 1)); } + + index = ent->index; + + VALUE *ptr = ROBJECT_IVPTR(obj); + if (index >= ROBJECT_NUMIV(obj)) { + rb_init_iv_list(obj, ROBJECT_NUMIV(obj), (uint32_t)iv_index_tbl->num_entries, iv_index_tbl); + ptr = ROBJECT_IVPTR(obj); + } + RB_OBJ_WRITE(obj, &ptr[index], val); + + return val; } /* fall through */ } |