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?= 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. --- compile.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 51477e9e20..48b3afd2d7 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 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 v1.2.3