summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-24 06:23:42 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-24 06:23:42 +0000
commit9d94a1a5a18f80974e017cb81790a08dad84faef (patch)
tree1ac1bf77739d757895acd4a33c708ac92589ee91 /enumerator.c
parentbcbeb5d008c1e91454b7f2c2d0e1d7b4735006e2 (diff)
* enumerator.c: Fix state handling for Lazy#drop
[bug #7696] [bug #7691] * test/ruby/test_lazy_enumerator.rb: test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/enumerator.c b/enumerator.c
index 769d940dab..9d7faa9ad3 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -1725,13 +1725,16 @@ lazy_drop_size(VALUE lazy)
static VALUE
lazy_drop_func(VALUE val, VALUE args, int argc, VALUE *argv)
{
- NODE *memo = RNODE(args);
-
- if (memo->u3.cnt == 0) {
+ long remain;
+ VALUE memo = rb_ivar_get(argv[0], id_memo);
+ if (NIL_P(memo)) {
+ memo = args;
+ }
+ if ((remain = NUM2LONG(memo)) == 0) {
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
}
else {
- memo->u3.cnt--;
+ rb_ivar_set(argv[0], id_memo, LONG2NUM(--remain));
}
return Qnil;
}
@@ -1739,15 +1742,13 @@ lazy_drop_func(VALUE val, VALUE args, int argc, VALUE *argv)
static VALUE
lazy_drop(VALUE obj, VALUE n)
{
- NODE *memo;
long len = NUM2LONG(n);
if (len < 0) {
rb_raise(rb_eArgError, "attempt to drop negative size");
}
- memo = NEW_MEMO(0, 0, len);
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
- lazy_drop_func, (VALUE) memo),
+ lazy_drop_func, n),
rb_ary_new3(1, n), lazy_drop_size);
}