diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-07 06:07:52 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-07 06:07:52 +0000 |
commit | ec0187ef156b26df99241db95e6487038771d29e (patch) | |
tree | 154ee32417920d359823deb344aec78ccd58ad84 | |
parent | ba80fd2bbfc034398e92295a776940db56f8fae6 (diff) | |
download | ruby-ec0187ef156b26df99241db95e6487038771d29e.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | enum.c | 19 |
2 files changed, 11 insertions, 13 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> * eval.c: fix typo in invoke_method documentation @@ -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) { |