1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* enum.c (enum_inject): reuse array for yield parameters.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-12-29 19:27:27 +00:00
parent 465fa424f0
commit 873b2f9fe3
2 changed files with 20 additions and 10 deletions

View file

@ -1,3 +1,7 @@
Sat Dec 30 04:25:29 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* enum.c (enum_inject): reuse array for yield parameters.
Sat Dec 30 02:54:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/stringio/stringio.c (strio_gets): accepts limit argument.

26
enum.c
View file

@ -335,13 +335,14 @@ enum_to_a(VALUE obj)
}
static VALUE
inject_i(VALUE i, VALUE *memo)
inject_i(VALUE i, VALUE memo)
{
if (*memo == Qundef) {
*memo = i;
if (RARRAY_PTR(memo)[0] == Qundef) {
RARRAY_PTR(memo)[0] = i;
}
else {
*memo = rb_yield_values(2, *memo, i);
RARRAY_PTR(memo)[1] = i;
RARRAY_PTR(memo)[0] = rb_yield(memo);
}
return Qnil;
}
@ -380,13 +381,18 @@ inject_i(VALUE i, VALUE *memo)
static VALUE
enum_inject(int argc, VALUE *argv, VALUE obj)
{
VALUE memo = Qundef;
VALUE memo, tmp;
if (rb_scan_args(argc, argv, "01", &memo) == 0)
memo = Qundef;
rb_block_call(obj, id_each, 0, 0, inject_i, (VALUE)&memo);
if (memo == Qundef) return Qnil;
return memo;
if (rb_scan_args(argc, argv, "01", &tmp) == 0) {
memo = rb_ary_new3(2, Qundef, Qnil);
}
else {
memo = rb_ary_new3(2, tmp, Qnil);
}
rb_block_call(obj, id_each, 0, 0, inject_i, (VALUE)memo);
tmp = RARRAY_PTR(memo)[0];
if (tmp == Qundef) return Qnil;
return tmp;
}
static VALUE