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

ruby-changes:61988

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

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

From 1f90690a1d2931e960a54056de089d163b689ed4 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: Thu, 11 Jun 2020 14:44:24 +0900
Subject: compile_branch_condition: 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/compile.c b/compile.c
index 51477e9..48b3afd 100644
--- a/compile.c
+++ b/compile.c
@@ -3927,35 +3927,35 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co https://github.com/ruby/ruby/blob/trunk/compile.c#L3927
       case NODE_LAMBDA:
 	/* printf("useless condition eliminate (%s)\n",  ruby_node_name(nd_type(cond))); */
 	ADD_INSNL(ret, nd_line(cond), jump, then_label);
-	break;
+        return COMPILE_OK;
       case NODE_FALSE:
       case NODE_NIL:
 	/* printf("useless condition eliminate (%s)\n", ruby_node_name(nd_type(cond))); */
 	ADD_INSNL(ret, nd_line(cond), jump, else_label);
-	break;
+        return COMPILE_OK;
       case NODE_LIST:
       case NODE_ARGSCAT:
       case NODE_DREGX:
       case NODE_DSTR:
 	CHECK(COMPILE_POPPED(ret, "branch condition", cond));
 	ADD_INSNL(ret, nd_line(cond), jump, then_label);
-	break;
+        return COMPILE_OK;
       case NODE_FLIP2:
 	CHECK(compile_flip_flop(iseq, ret, cond, TRUE, then_label, else_label));
-	break;
+        return COMPILE_OK;
       case NODE_FLIP3:
 	CHECK(compile_flip_flop(iseq, ret, cond, FALSE, then_label, else_label));
-	break;
+        return COMPILE_OK;
       case NODE_DEFINED:
 	CHECK(compile_defined_expr(iseq, ret, cond, Qfalse));
-	goto branch;
+        break;
       default:
 	CHECK(COMPILE(ret, "branch condition", cond));
-      branch:
-	ADD_INSNL(ret, nd_line(cond), branchunless, else_label);
-	ADD_INSNL(ret, nd_line(cond), jump, then_label);
-	break;
+        break;
     }
+
+    ADD_INSNL(ret, nd_line(cond), branchunless, else_label);
+    ADD_INSNL(ret, nd_line(cond), jump, then_label);
     return COMPILE_OK;
 }
 
-- 
cgit v0.10.2


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

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