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:
parent
465fa424f0
commit
873b2f9fe3
2 changed files with 20 additions and 10 deletions
|
@ -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>
|
Sat Dec 30 02:54:22 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* ext/stringio/stringio.c (strio_gets): accepts limit argument.
|
* ext/stringio/stringio.c (strio_gets): accepts limit argument.
|
||||||
|
|
26
enum.c
26
enum.c
|
@ -335,13 +335,14 @@ enum_to_a(VALUE obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
inject_i(VALUE i, VALUE *memo)
|
inject_i(VALUE i, VALUE memo)
|
||||||
{
|
{
|
||||||
if (*memo == Qundef) {
|
if (RARRAY_PTR(memo)[0] == Qundef) {
|
||||||
*memo = i;
|
RARRAY_PTR(memo)[0] = i;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*memo = rb_yield_values(2, *memo, i);
|
RARRAY_PTR(memo)[1] = i;
|
||||||
|
RARRAY_PTR(memo)[0] = rb_yield(memo);
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -380,13 +381,18 @@ inject_i(VALUE i, VALUE *memo)
|
||||||
static VALUE
|
static VALUE
|
||||||
enum_inject(int argc, VALUE *argv, VALUE obj)
|
enum_inject(int argc, VALUE *argv, VALUE obj)
|
||||||
{
|
{
|
||||||
VALUE memo = Qundef;
|
VALUE memo, tmp;
|
||||||
|
|
||||||
if (rb_scan_args(argc, argv, "01", &memo) == 0)
|
if (rb_scan_args(argc, argv, "01", &tmp) == 0) {
|
||||||
memo = Qundef;
|
memo = rb_ary_new3(2, Qundef, Qnil);
|
||||||
rb_block_call(obj, id_each, 0, 0, inject_i, (VALUE)&memo);
|
}
|
||||||
if (memo == Qundef) return Qnil;
|
else {
|
||||||
return memo;
|
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
|
static VALUE
|
||||||
|
|
Loading…
Add table
Reference in a new issue