diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-15 11:27:34 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-15 11:27:34 +0000 |
commit | 2511514d08c1ab33d7c1267e395150cbb1cac1cc (patch) | |
tree | 35e6f3d8d15c4fbc4be7faf1df96c9fe75a7964d | |
parent | 145c5827522be76c33b1617537e3953dbf6ebd0c (diff) | |
download | ruby-2511514d08c1ab33d7c1267e395150cbb1cac1cc.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | enum.c | 24 |
2 files changed, 29 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Tue Mar 15 20:21:01 2016 Tanaka Akira <akr@fsij.org> + + * 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@it.aoyama.ac.jp> * enc/unicode.c: Eliminating common code. @@ -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 (; 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; |