summaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-10 19:19:36 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-10 19:19:36 +0000
commit90c7902834ed4e414831669e1bf1ae3af4a4a91f (patch)
treec4bfaeb462fc57b54f0d43d09a914bab27b76400 /parse.y
parent2b9a99c5fd341137077a24ad83ee295e36578b42 (diff)
downloadruby-90c7902834ed4e414831669e1bf1ae3af4a4a91f.tar.gz
ruby-90c7902834ed4e414831669e1bf1ae3af4a4a91f.tar.xz
ruby-90c7902834ed4e414831669e1bf1ae3af4a4a91f.zip
* parse.y: optimize 'for' statement when one variable given.
* benchmark/bm_loop_for.rb: added. * benchmark/bm_loop_times.rb: modified. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y23
1 files changed, 17 insertions, 6 deletions
diff --git a/parse.y b/parse.y
index 88c423242..9dad7cd79 100644
--- a/parse.y
+++ b/parse.y
@@ -2772,16 +2772,27 @@ primary : literal
NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero),
rb_intern("kind_of?"), NEW_LIST(NEW_LIT(rb_cArray))),
0),
- NEW_DASGN_CURR(id,
- NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
- 0),
+ NEW_DASGN_CURR(id,
+ NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
+ 0),
node_assign($2, NEW_DVAR(id)));
+
+ args = new_args(m, 0, id, 0, 0);
}
else {
- m->nd_next = node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id));
+ if (nd_type($2) == NODE_LASGN ||
+ nd_type($2) == NODE_DASGN ||
+ nd_type($2) == NODE_DASGN_CURR) {
+ $2->nd_value = NEW_DVAR(id);
+ m->nd_plen = 1;
+ m->nd_next = $2;
+ args = new_args(m, 0, 0, 0, 0);
+ }
+ else {
+ m->nd_next = node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id));
+ args = new_args(m, 0, id, 0, 0);
+ }
}
-
- args = new_args(m, 0, id, 0, 0);
scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
tbl[0] = 1; tbl[1] = id;
$$ = NEW_FOR(0, $5, scope);