Skip to content

Commit

Permalink
Avoid slow path ivar setting
Browse files Browse the repository at this point in the history
If the ivar index table exists, we can avoid the slowest path for
setting ivars.
  • Loading branch information
tenderlove committed Nov 9, 2020
1 parent 6778ba4 commit f259906
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions vm_insnhelper.c
Expand Up @@ -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 */
}
Expand Down

0 comments on commit f259906

Please sign in to comment.