diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-11 14:44:24 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-29 11:05:41 +0900 |
commit | 1f90690a1d2931e960a54056de089d163b689ed4 (patch) | |
tree | b1beb5514c0035b0cb7b9a72d29042e91c8e9cd8 /compile.c | |
parent | a6b1454a5d6a9d489e3ed70114e43a5d3a9467ec (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -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; } |