mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enumerator.c: Support for lazy.cycle.size
[Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7a31096255
commit
0814c4ac64
4 changed files with 19 additions and 2 deletions
2
enum.c
2
enum.c
|
@ -2235,7 +2235,7 @@ cycle_i(VALUE i, VALUE ary, int argc, VALUE *argv)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
VALUE
|
||||
enum_cycle_size(VALUE self, VALUE args)
|
||||
{
|
||||
long mul;
|
||||
|
|
|
@ -1740,6 +1740,11 @@ lazy_drop_while(VALUE obj)
|
|||
Qnil, 0);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
lazy_cycle_size(VALUE lazy) {
|
||||
return enum_cycle_size(rb_ivar_get(lazy, id_receiver), rb_ivar_get(lazy, id_arguments));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
lazy_cycle_func(VALUE val, VALUE m, int argc, VALUE *argv)
|
||||
{
|
||||
|
@ -1764,7 +1769,7 @@ lazy_cycle(int argc, VALUE *argv, VALUE obj)
|
|||
return lazy_set_method(rb_block_call(rb_cLazy, id_new, len,
|
||||
RARRAY_PTR(args), lazy_cycle_func,
|
||||
args /* prevent from GC */),
|
||||
rb_ary_new4(argc, argv), 0);
|
||||
rb_ary_new4(argc, argv), lazy_cycle_size);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
|
@ -87,6 +87,9 @@ ID rb_id_encoding(void);
|
|||
/* encoding.c */
|
||||
void rb_gc_mark_encodings(void);
|
||||
|
||||
/* enum.c */
|
||||
VALUE enum_cycle_size(VALUE self, VALUE args);
|
||||
|
||||
/* error.c */
|
||||
NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
|
||||
VALUE rb_check_backtrace(VALUE);
|
||||
|
|
|
@ -346,5 +346,14 @@ EOS
|
|||
assert_equal 0, lazy.drop(4).size
|
||||
assert_equal Float::INFINITY, loop.lazy.drop(4).size
|
||||
assert_equal nil, lazy.select{}.drop(4).size
|
||||
|
||||
assert_equal 0, lazy.cycle(0).size
|
||||
assert_equal 6, lazy.cycle(2).size
|
||||
assert_equal 3 << 80, 4.times.inject(lazy){|enum| enum.cycle(1 << 20)}.size
|
||||
assert_equal Float::INFINITY, lazy.cycle.size
|
||||
assert_equal Float::INFINITY, loop.lazy.cycle(4).size
|
||||
assert_equal Float::INFINITY, loop.lazy.cycle.size
|
||||
assert_equal nil, lazy.select{}.cycle(4).size
|
||||
assert_equal nil, lazy.select{}.cycle.size
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue