From 2511514d08c1ab33d7c1267e395150cbb1cac1cc Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 15 Mar 2016 11:27:34 +0000 Subject: * enum.c (enum_inject): Implement the specialized code for self is an array and a symbol operator is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ enum.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index 317962c555..2d1618d1f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Mar 15 20:21:01 2016 Tanaka Akira + + * 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 * enc/unicode.c: Eliminating common code. diff --git a/enum.c b/enum.c index 681d58f14a..49cd8ef7af 100644 --- a/enum.c +++ b/enum.c @@ -701,6 +701,30 @@ enum_inject(int argc, VALUE *argv, VALUE obj) 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 (; iv1 == Qundef) return Qnil; -- cgit v1.2.3