ruby-changes:8225
From: ko1 <ko1@a...>
Date: Sat, 11 Oct 2008 04:21:34 +0900 (JST)
Subject: [ruby-changes:8225] Ruby:r19753 (trunk): * parse.y: optimize 'for' statement when one variable given.
ko1 2008-10-11 04:19:36 +0900 (Sat, 11 Oct 2008) New Revision: 19753 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19753 Log: * parse.y: optimize 'for' statement when one variable given. * benchmark/bm_loop_for.rb: added. * benchmark/bm_loop_times.rb: modified. Added files: trunk/benchmark/bm_loop_for.rb Modified files: trunk/ChangeLog trunk/benchmark/bm_loop_times.rb trunk/parse.y Index: ChangeLog =================================================================== --- ChangeLog (revision 19752) +++ ChangeLog (revision 19753) @@ -1,3 +1,11 @@ +Sat Oct 11 03:54:05 2008 Koichi Sasada <ko1@a...> + + * 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@r...> * lib/csv/csv.rb: Added support for Encoding::default_internal. Index: parse.y =================================================================== --- parse.y (revision 19752) +++ parse.y (revision 19753) @@ -2772,16 +2772,27 @@ 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); Index: benchmark/bm_loop_for.rb =================================================================== --- benchmark/bm_loop_for.rb (revision 0) +++ benchmark/bm_loop_for.rb (revision 19753) @@ -0,0 +1,3 @@ +for i in 1..30_000_000 + # +end Index: benchmark/bm_loop_times.rb =================================================================== --- benchmark/bm_loop_times.rb (revision 19752) +++ benchmark/bm_loop_times.rb (revision 19753) @@ -1 +1 @@ -30000000.times{|e|} +30_000_000.times{|e|} -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/