mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enum.c (enum_each_with_index): make different arrays at each
iteration. [ruby-dev:32181] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ba80fd2bbf
commit
ec0187ef15
2 changed files with 10 additions and 12 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Nov 7 15:07:51 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* enum.c (enum_each_with_index): make different arrays at each
|
||||||
|
iteration. [ruby-dev:32181]
|
||||||
|
|
||||||
Tue Nov 7 05:17:24 2007 David Flanagan <davidflanagan@ruby-lang.org>
|
Tue Nov 7 05:17:24 2007 David Flanagan <davidflanagan@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c: fix typo in invoke_method documentation
|
* eval.c: fix typo in invoke_method documentation
|
||||||
|
|
17
enum.c
17
enum.c
|
@ -1293,15 +1293,9 @@ enum_member(VALUE obj, VALUE val)
|
||||||
static VALUE
|
static VALUE
|
||||||
each_with_index_i(VALUE val, VALUE memo)
|
each_with_index_i(VALUE val, VALUE memo)
|
||||||
{
|
{
|
||||||
long n;
|
long n = (*(VALUE *)memo)++;
|
||||||
VALUE idx = RARRAY_PTR(memo)[1];
|
|
||||||
|
|
||||||
RARRAY_PTR(memo)[0] = val;
|
return rb_yield(rb_ary_new3(2, val, INT2NUM(n)));
|
||||||
rb_yield(memo);
|
|
||||||
n = NUM2LONG(idx);
|
|
||||||
n++;
|
|
||||||
RARRAY_PTR(memo)[1] = INT2NUM(n);
|
|
||||||
return Qnil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1322,12 +1316,12 @@ each_with_index_i(VALUE val, VALUE memo)
|
||||||
static VALUE
|
static VALUE
|
||||||
enum_each_with_index(int argc, VALUE *argv, VALUE obj)
|
enum_each_with_index(int argc, VALUE *argv, VALUE obj)
|
||||||
{
|
{
|
||||||
VALUE memo;
|
long memo;
|
||||||
|
|
||||||
RETURN_ENUMERATOR(obj, argc, argv);
|
RETURN_ENUMERATOR(obj, argc, argv);
|
||||||
|
|
||||||
memo = rb_ary_new3(2, Qnil, INT2FIX(0));
|
memo = 0;
|
||||||
rb_block_call(obj, id_each, argc, argv, each_with_index_i, memo);
|
rb_block_call(obj, id_each, argc, argv, each_with_index_i, (VALUE)&memo);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1534,7 +1528,6 @@ enum_drop_while(VALUE obj)
|
||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
cycle_i(VALUE i, VALUE ary)
|
cycle_i(VALUE i, VALUE ary)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue