diff options
author | HParker <HParker@github.com> | 2022-09-21 14:12:45 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2022-09-22 09:47:13 -0700 |
commit | fbaac837cfba23a9d34dc7ee144d7940248222a2 (patch) | |
tree | 9421bf92d889c1aabfc8f10eac9480d42174fa2a /compile.c | |
parent | aafbc9068f96e5e1f7f5c2c1fa6cba01ec8422db (diff) | |
download | ruby-fbaac837cfba23a9d34dc7ee144d7940248222a2.tar.gz |
avoid extra dup and pop in compile_op_asgn2
Co-authored-by: John Hawthorn <jhawthorn@github.com>
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -8663,6 +8663,17 @@ compile_op_asgn2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node lfin: # o ? pop # o + # or (popped) + if lcfin # r + eval v # r v + send a= # ? + jump lfin # ? + + lcfin: # r + + lfin: # ? + pop # + # and dup # r o o unless lcfin @@ -8691,32 +8702,36 @@ compile_op_asgn2(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node ADD_SEND_WITH_FLAG(ret, node, vid, INT2FIX(0), INT2FIX(asgnflag)); if (atype == idOROP || atype == idANDOP) { - ADD_INSN(ret, node, dup); + if (!popped) { + ADD_INSN(ret, node, dup); + } if (atype == idOROP) { ADD_INSNL(ret, node, branchif, lcfin); } else { /* idANDOP */ ADD_INSNL(ret, node, branchunless, lcfin); } - ADD_INSN(ret, node, pop); + if (!popped) { + ADD_INSN(ret, node, pop); + } CHECK(COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value)); - ADD_INSN(ret, node, swap); - ADD_INSN1(ret, node, topn, INT2FIX(1)); + if (!popped) { + ADD_INSN(ret, node, swap); + ADD_INSN1(ret, node, topn, INT2FIX(1)); + } ADD_SEND_WITH_FLAG(ret, node, aid, INT2FIX(1), INT2FIX(asgnflag)); ADD_INSNL(ret, node, jump, lfin); ADD_LABEL(ret, lcfin); - ADD_INSN(ret, node, swap); + if (!popped) { + ADD_INSN(ret, node, swap); + } ADD_LABEL(ret, lfin); ADD_INSN(ret, node, pop); if (lskip) { ADD_LABEL(ret, lskip); } - if (popped) { - /* we can apply more optimize */ - ADD_INSN(ret, node, pop); - } } else { CHECK(COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value)); @@ -8848,9 +8863,7 @@ compile_op_log(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, } ADD_LABEL(ret, lassign); - CHECK(COMPILE_(ret, "NODE_OP_ASGN_AND/OR#nd_value", node->nd_value, popped)); - ADD_LABEL(ret, lfin); return COMPILE_OK; } |