Project

General

Profile

Bug #6428 » lazy_take_recycle.patch

nagachika (Tomoyuki Chikanaga), 05/13/2012 01:52 AM

View differences:

enumerator.c
1533 1533

  
1534 1534
    rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
1535 1535
    if (--memo->u3.cnt == 0) {
1536
	memo->u3.cnt = memo->u2.argc;
1536 1537
	return Qundef;
1537 1538
    }
1538 1539
    else {
......
1557 1558
	argv[2] = INT2NUM(0);
1558 1559
	argc = 3;
1559 1560
    }
1560
    memo = NEW_MEMO(0, 0, len);
1561
    memo = NEW_MEMO(0, len, len);
1561 1562
    return lazy_set_method(rb_block_call(rb_cLazy, id_new, argc, argv,
1562 1563
					 lazy_take_func, (VALUE) memo),
1563 1564
			   rb_ary_new3(1, n));
test/ruby/test_lazy_enumerator.rb
229 229
    assert_equal(nil, a.current)
230 230
  end
231 231

  
232
  def test_take_recycle
233
    a = Step.new(1..10)
234
    take5 = a.lazy.take(5)
235
    assert_equal((1..5).to_a, take5.force)
236
    assert_equal((1..5).to_a, take5.force)
237
  end
238

  
232 239
  def test_take_while
233 240
    a = Step.new(1..10)
234 241
    assert_equal(1, a.take_while {|i| i < 5}.first)