[前][次][番号順一覧][スレッド一覧]

ruby-changes:62031

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:08:07 +0900 (JST)
Subject: [ruby-changes:62031] 1bf0d36171 (master): vm_getivar: do not goto into a branch

https://git.ruby-lang.org/ruby.git/commit/?id=1bf0d36171

From 1bf0d3617172da9fe8b5e99796d8d85412c14f6a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Mon, 22 Jun 2020 11:07:26 +0900
Subject: 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.

diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 5c85d14..294099b 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) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1080
             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) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1091
                 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;
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]