summaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-07 06:07:52 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-07 06:07:52 +0000
commit1518976cc628ecd4e598d4f53271ee354b12f4d4 (patch)
tree154ee32417920d359823deb344aec78ccd58ad84 /enum.c
parentaeebd0be3c4141cab8f148b8b41a01e2498470da (diff)
downloadruby-1518976cc628ecd4e598d4f53271ee354b12f4d4.tar.gz
ruby-1518976cc628ecd4e598d4f53271ee354b12f4d4.tar.xz
ruby-1518976cc628ecd4e598d4f53271ee354b12f4d4.zip
* enum.c (enum_each_with_index): make different arrays at each
iteration. [ruby-dev:32181] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/enum.c b/enum.c
index 5beb900d4..096772dd2 100644
--- a/enum.c
+++ b/enum.c
@@ -1293,15 +1293,9 @@ enum_member(VALUE obj, VALUE val)
static VALUE
each_with_index_i(VALUE val, VALUE memo)
{
- long n;
- VALUE idx = RARRAY_PTR(memo)[1];
-
- RARRAY_PTR(memo)[0] = val;
- rb_yield(memo);
- n = NUM2LONG(idx);
- n++;
- RARRAY_PTR(memo)[1] = INT2NUM(n);
- return Qnil;
+ long n = (*(VALUE *)memo)++;
+
+ return rb_yield(rb_ary_new3(2, val, INT2NUM(n)));
}
/*
@@ -1322,12 +1316,12 @@ each_with_index_i(VALUE val, VALUE memo)
static VALUE
enum_each_with_index(int argc, VALUE *argv, VALUE obj)
{
- VALUE memo;
+ long memo;
RETURN_ENUMERATOR(obj, argc, argv);
- memo = rb_ary_new3(2, Qnil, INT2FIX(0));
- rb_block_call(obj, id_each, argc, argv, each_with_index_i, memo);
+ memo = 0;
+ rb_block_call(obj, id_each, argc, argv, each_with_index_i, (VALUE)&memo);
return obj;
}
@@ -1534,7 +1528,6 @@ enum_drop_while(VALUE obj)
return args[0];
}
-
static VALUE
cycle_i(VALUE i, VALUE ary)
{