mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enumerator.c: Fix state handling for Lazy#drop_while
[bug #7696] [bug #7691] * test/ruby/test_lazy_enumerator.rb: test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
de0e887635
commit
bcbeb5d008
2 changed files with 12 additions and 9 deletions
14
enumerator.c
14
enumerator.c
|
@ -1754,12 +1754,11 @@ lazy_drop(VALUE obj, VALUE n)
|
|||
static VALUE
|
||||
lazy_drop_while_func(VALUE val, VALUE args, int argc, VALUE *argv)
|
||||
{
|
||||
NODE *memo = RNODE(args);
|
||||
|
||||
if (!memo->u3.state && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) {
|
||||
memo->u3.state = TRUE;
|
||||
VALUE memo = rb_ivar_get(argv[0], id_memo);
|
||||
if (NIL_P(memo) && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) {
|
||||
rb_ivar_set(argv[0], id_memo, memo = Qtrue);
|
||||
}
|
||||
if (memo->u3.state) {
|
||||
if (memo == Qtrue) {
|
||||
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
|
||||
}
|
||||
return Qnil;
|
||||
|
@ -1768,14 +1767,11 @@ lazy_drop_while_func(VALUE val, VALUE args, int argc, VALUE *argv)
|
|||
static VALUE
|
||||
lazy_drop_while(VALUE obj)
|
||||
{
|
||||
NODE *memo;
|
||||
|
||||
if (!rb_block_given_p()) {
|
||||
rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
|
||||
}
|
||||
memo = NEW_MEMO(0, 0, FALSE);
|
||||
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
|
||||
lazy_drop_while_func, (VALUE) memo),
|
||||
lazy_drop_while_func, 0),
|
||||
Qnil, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -250,6 +250,13 @@ class TestLazyEnumerator < Test::Unit::TestCase
|
|||
assert_equal([*(1..5)]*5, take5.flat_map{take5}.force, bug7696)
|
||||
end
|
||||
|
||||
def test_drop_while_nested
|
||||
bug7696 = '[ruby-core:51470]'
|
||||
a = Step.new(1..10)
|
||||
drop5 = a.lazy.drop_while{|x| x < 6}
|
||||
assert_equal([*(6..10)]*5, drop5.flat_map{drop5}.force, bug7696)
|
||||
end
|
||||
|
||||
def test_take_rewound
|
||||
bug7696 = '[ruby-core:51470]'
|
||||
e=(1..42).lazy.take(2)
|
||||
|
|
Loading…
Reference in a new issue