1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* vm_insnhelper.c (vm_getivar): describe fast-path explicit

(compiler frindly). [Bug #12274].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tarui 2016-05-11 15:04:27 +00:00
parent 44916ec448
commit 0b8f8ac54e
2 changed files with 23 additions and 22 deletions

View file

@ -1,3 +1,8 @@
Wed May 11 23:59:47 2016 Masaya Tarui <tarui@ruby-lang.org>
* vm_insnhelper.c (vm_getivar): describe fast-path explicit
(compiler frindly). [Bug #12274].
Wed May 11 21:30:07 2016 Masaya Tarui <tarui@ruby-lang.org> Wed May 11 21:30:07 2016 Masaya Tarui <tarui@ruby-lang.org>
* compile.c (iseq_compile_each): share InlineCache during same * compile.c (iseq_compile_each): share InlineCache during same

View file

@ -785,18 +785,20 @@ INLINE VALUE
vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr) vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr)
{ {
#if USE_IC_FOR_IVAR #if USE_IC_FOR_IVAR
if (RB_TYPE_P(obj, T_OBJECT)) { if (LIKELY(RB_TYPE_P(obj, T_OBJECT))) {
VALUE val = Qundef; VALUE val = Qundef;
VALUE klass = RBASIC(obj)->klass; if (LIKELY(is_attr ? cc->aux.index > 0 : ic->ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass))) {
const uint32_t len = ROBJECT_NUMIV(obj);
const VALUE *const ptr = ROBJECT_IVPTR(obj);
if (LIKELY(is_attr ? cc->aux.index > 0 : ic->ic_serial == RCLASS_SERIAL(klass))) {
st_index_t index = !is_attr ? ic->ic_value.index : (cc->aux.index - 1); st_index_t index = !is_attr ? ic->ic_value.index : (cc->aux.index - 1);
if (LIKELY(index < ROBJECT_NUMIV(obj))) {
if (index < len) { val = ROBJECT_IVPTR(obj)[index];
val = ptr[index];
} }
undef_check:
if (UNLIKELY(val == Qundef)) {
if (!is_attr && RTEST(ruby_verbose))
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
val = Qnil;
}
return val;
} }
else { else {
st_data_t index; st_data_t index;
@ -804,26 +806,20 @@ vm_getivar(VALUE obj, ID id, IC ic, struct rb_call_cache *cc, int is_attr)
if (iv_index_tbl) { if (iv_index_tbl) {
if (st_lookup(iv_index_tbl, id, &index)) { if (st_lookup(iv_index_tbl, id, &index)) {
if (index < len) { if (index < ROBJECT_NUMIV(obj)) {
val = ptr[index]; val = ROBJECT_IVPTR(obj)[index];
} }
if (!is_attr) { if (!is_attr) {
ic->ic_value.index = index; ic->ic_value.index = index;
ic->ic_serial = RCLASS_SERIAL(klass); ic->ic_serial = RCLASS_SERIAL(RBASIC(obj)->klass);
} }
else { /* call_info */ else { /* call_info */
cc->aux.index = (int)index + 1; cc->aux.index = (int)index + 1;
} }
} }
} }
goto undef_check;
} }
if (UNLIKELY(val == Qundef)) {
if (!is_attr && RTEST(ruby_verbose))
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
val = Qnil;
}
return val;
} }
#endif /* USE_IC_FOR_IVAR */ #endif /* USE_IC_FOR_IVAR */
if (is_attr) if (is_attr)
@ -837,7 +833,7 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_
#if USE_IC_FOR_IVAR #if USE_IC_FOR_IVAR
rb_check_frozen(obj); rb_check_frozen(obj);
if (RB_TYPE_P(obj, T_OBJECT)) { if (LIKELY(RB_TYPE_P(obj, T_OBJECT))) {
VALUE klass = RBASIC(obj)->klass; VALUE klass = RBASIC(obj)->klass;
st_data_t index; st_data_t index;
@ -874,13 +870,13 @@ vm_setivar(VALUE obj, ID id, VALUE val, IC ic, struct rb_call_cache *cc, int is_
return rb_ivar_set(obj, id, val); return rb_ivar_set(obj, id, val);
} }
static VALUE static inline VALUE
vm_getinstancevariable(VALUE obj, ID id, IC ic) vm_getinstancevariable(VALUE obj, ID id, IC ic)
{ {
return vm_getivar(obj, id, ic, 0, 0); return vm_getivar(obj, id, ic, 0, 0);
} }
static void static inline void
vm_setinstancevariable(VALUE obj, ID id, VALUE val, IC ic) vm_setinstancevariable(VALUE obj, ID id, VALUE val, IC ic)
{ {
vm_setivar(obj, id, val, ic, 0, 0); vm_setivar(obj, id, val, ic, 0, 0);