summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-22 11:07:26 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commit1bf0d3617172da9fe8b5e99796d8d85412c14f6a (patch)
treef47727b520d037d2ae17b41b2021c1ed44c56ace
parent6e67b30503f2931d9538d439545c3b1cff51fc80 (diff)
vm_getivar: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3247
-rw-r--r--vm_insnhelper.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 5c85d14967..294099b58f 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1080,23 +1080,7 @@ vm_getivar(VALUE obj, ID id, IVC ic, const struct rb_callcache *cc, int is_attr)
iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
numiv = ROBJECT_NUMIV(obj);
ivptr = ROBJECT_IVPTR(obj);
-
- fill:
- if (iv_index_tbl) {
- if (st_lookup(iv_index_tbl, id, &index)) {
- if (!is_attr) {
- ic->index = index;
- ic->ic_serial = RCLASS_SERIAL(RBASIC(obj)->klass);
- }
- else { /* call_info */
- vm_cc_attr_index_set(cc, (int)index + 1);
- }
-
- if (index < numiv) {
- val = ivptr[index];
- }
- }
- }
+ goto fill;
}
else if (FL_TEST_RAW(obj, FL_EXIVAR)) {
struct gen_ivtbl *ivtbl;
@@ -1107,12 +1091,32 @@ vm_getivar(VALUE obj, ID id, IVC ic, const struct rb_callcache *cc, int is_attr)
iv_index_tbl = RCLASS_IV_INDEX_TBL(rb_obj_class(obj));
goto fill;
}
+ else {
+ goto ret;
+ }
}
else {
// T_CLASS / T_MODULE
goto general_path;
}
+ fill:
+ if (iv_index_tbl) {
+ if (st_lookup(iv_index_tbl, id, &index)) {
+ if (!is_attr) {
+ ic->index = index;
+ ic->ic_serial = RCLASS_SERIAL(RBASIC(obj)->klass);
+ }
+ else { /* call_info */
+ vm_cc_attr_index_set(cc, (int)index + 1);
+ }
+
+ if (index < numiv) {
+ val = ivptr[index];
+ }
+ }
+ }
+
ret:
if (LIKELY(val != Qundef)) {
return val;