summaryrefslogtreecommitdiff
path: root/ext/enumerator
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-02 07:38:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-02 07:38:21 +0000
commit0b4597eccfb5ee078e546c910f2f3cee31d3274b (patch)
tree753298956c53bf0156ad443fabaeebd9fa391be1 /ext/enumerator
parent7b45f992889e20ff28efa8bbc5c2b000704c6b59 (diff)
* ext/enumerator/enumerator.c (each_cons_i): pass copy of an
internal consequent array. [ruby-talk:118691] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/enumerator')
-rw-r--r--ext/enumerator/enumerator.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/ext/enumerator/enumerator.c b/ext/enumerator/enumerator.c
index 6e47330cef..74785569e7 100644
--- a/ext/enumerator/enumerator.c
+++ b/ext/enumerator/enumerator.c
@@ -87,15 +87,13 @@ each_cons_i(val, memo)
{
VALUE ary = memo->u1.value;
long size = memo->u3.cnt;
- long len = RARRAY(ary)->len;
- if (len == size) {
+ if (RARRAY(ary)->len == size) {
rb_ary_shift(ary);
- rb_ary_push(ary, val);
- rb_yield(ary);
- } else {
- rb_ary_push(ary, val);
- if (len + 1 == size) rb_yield(ary);
+ }
+ rb_ary_push(ary, val);
+ if (RARRAY(ary)->len == size) {
+ rb_yield(rb_ary_dup(ary));
}
return Qnil;
}
@@ -106,7 +104,6 @@ enum_each_cons(obj, n)
{
long size = NUM2LONG(n);
NODE *memo;
- VALUE ary;
if (size <= 0) rb_raise(rb_eArgError, "invalid size");
memo = rb_node_newnode(NODE_MEMO, rb_ary_new2(size), 0, size);