From ec0187ef156b26df99241db95e6487038771d29e Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 7 Nov 2007 06:07:52 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ enum.c | 17 +++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index f18e7d779e..3a9920f3a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Nov 7 15:07:51 2007 Nobuyoshi Nakada + + * enum.c (enum_each_with_index): make different arrays at each + iteration. [ruby-dev:32181] + Tue Nov 7 05:17:24 2007 David Flanagan * eval.c: fix typo in invoke_method documentation diff --git a/enum.c b/enum.c index 5beb900d4f..096772dd2c 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]; + long n = (*(VALUE *)memo)++; - RARRAY_PTR(memo)[0] = val; - rb_yield(memo); - n = NUM2LONG(idx); - n++; - RARRAY_PTR(memo)[1] = INT2NUM(n); - return Qnil; + 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) {