-
Notifications
You must be signed in to change notification settings - Fork 6
/
llrb_insn_getinstancevariable.c
55 lines (51 loc) · 1.36 KB
/
llrb_insn_getinstancevariable.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "cruby.h"
static VALUE __attribute__ ((noinline))
vm_getivar_else(VALUE obj, ID id, IC ic)
{
st_data_t index;
struct st_table *iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
VALUE val = Qundef;
if (iv_index_tbl) {
if (st_lookup(iv_index_tbl, id, &index)) {
if (index < ROBJECT_NUMIV(obj)) {
val = ROBJECT_IVPTR(obj)[index];
}
ic->ic_value.index = index;
ic->ic_serial = RCLASS_SERIAL(RBASIC(obj)->klass);
}
}
if (UNLIKELY(val == Qundef)) {
if (RTEST(ruby_verbose))
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
val = Qnil;
}
return val;
}
static inline VALUE
vm_getivar(VALUE obj, ID id, IC ic)
{
if (LIKELY(RB_TYPE_P(obj, T_OBJECT))) {
VALUE val = Qundef;
if (LIKELY(ic->ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass))) {
st_index_t index = ic->ic_value.index;
if (LIKELY(index < ROBJECT_NUMIV(obj))) {
val = ROBJECT_IVPTR(obj)[index];
}
if (UNLIKELY(val == Qundef)) {
if (RTEST(ruby_verbose))
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
val = Qnil;
}
return val;
}
else {
vm_getivar_else(obj, id, ic);
}
}
return rb_ivar_get(obj, id);
}
VALUE
llrb_insn_getinstancevariable(VALUE obj, ID id, VALUE ic_v)
{
return vm_getivar(obj, id, (IC)ic_v);
}