Skip to content

Commit

Permalink
* parse.y: optimize 'for' statement when one variable given.
Browse files Browse the repository at this point in the history
* 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
ko1 committed Oct 10, 2008
1 parent 254937c commit 3f71078
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -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> 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. * lib/csv/csv.rb: Added support for Encoding::default_internal.
Expand Down
3 changes: 3 additions & 0 deletions benchmark/bm_loop_for.rb
@@ -0,0 +1,3 @@
for i in 1..30_000_000
#
end
2 changes: 1 addition & 1 deletion benchmark/bm_loop_times.rb
@@ -1 +1 @@
30000000.times{|e|} 30_000_000.times{|e|}
23 changes: 17 additions & 6 deletions parse.y
Expand Up @@ -2772,16 +2772,27 @@ primary : literal
NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero), NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero),
rb_intern("kind_of?"), NEW_LIST(NEW_LIT(rb_cArray))), rb_intern("kind_of?"), NEW_LIST(NEW_LIT(rb_cArray))),
0), 0),
NEW_DASGN_CURR(id, NEW_DASGN_CURR(id,
NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)), NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
0), 0),
node_assign($2, NEW_DVAR(id))); node_assign($2, NEW_DVAR(id)));

args = new_args(m, 0, id, 0, 0);
} }
else { 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); scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
tbl[0] = 1; tbl[1] = id; tbl[0] = 1; tbl[1] = id;
$$ = NEW_FOR(0, $5, scope); $$ = NEW_FOR(0, $5, scope);
Expand Down

0 comments on commit 3f71078

Please sign in to comment.