aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-16 11:58:52 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-16 11:58:52 +0000
commit4aa088c72f98308bd6b47ae5bc09c79f358f18d8 (patch)
treead59a5421cb73dec8c29f3b97d024c556cbaec02 /compile.c
parent191796051046aa5423585fc027a4c8d470c9438d (diff)
downloadruby-4aa088c72f98308bd6b47ae5bc09c79f358f18d8.tar.gz
compile.c: massign optimization
* compile.c (compile_massign): optimization for special case, assignments by aset or attrset. http://kokizzu.blogspot.jp/2015/02/c-java-hhvm-ruby-nodejsrhinojscspidermo.html http://www.atdot.net/~ko1/diary/201502.html#d16 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index 0745e1a4c6..4e9c9b31cb 100644
--- a/compile.c
+++ b/compile.c
@@ -2782,6 +2782,7 @@ compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int poped)
if (!poped || splatn || !compile_massign_opt(iseq, ret, rhsn, lhsn)) {
int llen = 0;
+ int expand = 1;
DECL_ANCHOR(lhsseq);
INIT_ANCHOR(lhsseq);
@@ -2797,9 +2798,30 @@ compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int poped)
if (!poped) {
ADD_INSN(ret, nd_line(node), dup);
}
-
- ADD_INSN2(ret, nd_line(node), expandarray,
- INT2FIX(llen), INT2FIX(lhs_splat));
+ else if (!lhs_splat) {
+ INSN *last = (INSN*)ret->last;
+ if (last->link.type == ISEQ_ELEMENT_INSN &&
+ last->insn_id == BIN(newarray) &&
+ last->operand_size == 1 &&
+ OPERAND_AT(last, 0) == INT2FIX(llen)) {
+ /* special case: assign to aset or attrset */
+ if (llen == 2) {
+ POP_ELEMENT(ret);
+ ADD_INSN(ret, nd_line(node), swap);
+ expand = 0;
+ }
+#if 0
+ else if (llen > 2) {
+ last->insn_id = BIN(reverse);
+ expand = 0;
+ }
+#endif
+ }
+ }
+ if (expand) {
+ ADD_INSN2(ret, nd_line(node), expandarray,
+ INT2FIX(llen), INT2FIX(lhs_splat));
+ }
ADD_SEQ(ret, lhsseq);
if (lhs_splat) {