ruby-changes:42045
From: akr <ko1@a...>
Date: Tue, 15 Mar 2016 20:27:40 +0900 (JST)
Subject: [ruby-changes:42045] akr:r54119 (trunk): * enum.c (enum_inject): Implement the specialized code for self is an
akr 2016-03-15 20:27:34 +0900 (Tue, 15 Mar 2016) New Revision: 54119 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54119 Log: * enum.c (enum_inject): Implement the specialized code for self is an array and a symbol operator is given. Modified files: trunk/ChangeLog trunk/enum.c Index: enum.c =================================================================== --- enum.c (revision 54118) +++ enum.c (revision 54119) @@ -701,6 +701,30 @@ enum_inject(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/enum.c#L701 iter = inject_op_i; break; } + + if (iter == inject_op_i && + SYMBOL_P(op) && + RB_TYPE_P(obj, T_ARRAY) && + rb_method_basic_definition_p(CLASS_OF(obj), id_each)) { + VALUE v; + long i; + if (RARRAY_LEN(obj) == 0) + return init == Qundef ? Qnil : init; + if (init == Qundef) { + v = RARRAY_AREF(obj, 0); + i = 1; + } + else { + v = init; + i = 0; + } + id = SYM2ID(op); + for (; i<RARRAY_LEN(obj); i++) { + v = rb_funcall(v, id, 1, RARRAY_AREF(obj, i)); + } + return v; + } + memo = MEMO_NEW(init, Qnil, op); rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo); if (memo->v1 == Qundef) return Qnil; Index: ChangeLog =================================================================== --- ChangeLog (revision 54118) +++ ChangeLog (revision 54119) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Mar 15 20:21:01 2016 Tanaka Akira <akr@f...> + + * enum.c (enum_inject): Implement the specialized code for self is an + array and a symbol operator is given. + Tue Mar 15 16:29:51 2016 Martin Duerst <duerst@i...> * enc/unicode.c: Eliminating common code. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/