Permalink
Browse files

* parse.y: optimize 'for' statement when one variable given.

* benchmark/bm_loop_for.rb: added.
* benchmark/bm_loop_times.rb: modified.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 254937c commit 3f710785f0508d93795b316b78dc24987cf47370 @ko1 ko1 committed Oct 10, 2008
Showing with 29 additions and 7 deletions.
  1. +8 −0 ChangeLog
  2. +3 −0 benchmark/bm_loop_for.rb
  3. +1 −1 benchmark/bm_loop_times.rb
  4. +17 −6 parse.y
View
@@ -1,3 +1,11 @@
+Sat Oct 11 03:54:05 2008 Koichi Sasada <ko1@atdot.net>
+
+ * parse.y: optimize 'for' statement when one variable given.
+
+ * benchmark/bm_loop_for.rb: added.
+
+ * benchmark/bm_loop_times.rb: modified.
+
Sat Oct 11 12:09:05 2008 James Edward Gray II <jeg2@ruby-lang.org>
* lib/csv/csv.rb: Added support for Encoding::default_internal.
View
@@ -0,0 +1,3 @@
+for i in 1..30_000_000
+ #
+end
@@ -1 +1 @@
-30000000.times{|e|}
+30_000_000.times{|e|}
View
23 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);

0 comments on commit 3f71078

Please sign in to comment.