summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-05 03:49:59 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-05 03:49:59 +0000
commit1677cbce9d7c72cca83d1b7d48cb85a17e74abcc (patch)
treecc1dd1c678470e3c26343e054f5443ff1eac77bb /enumerator.c
parent44cd5f21e9d06ccc09ba8e12fb53d64f0df059a3 (diff)
* enumerator.c: Use to_enum for Enumerable methods returning Enumerators.
This makes Lazy#cycle no longer needed, so it was removed. Make Enumerator#chunk and slice_before return lazy Enumerators. [Bug #7715] * internal.h: Remove ref to rb_enum_cycle_size; no longer needed * enum.c: Make enum_cycle_size static. * test/ruby/test_lazy_enumerator.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/enumerator.c b/enumerator.c
index 682e9a7..a8bc787 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -463,7 +463,13 @@ lazy_to_enum_i(VALUE self, VALUE meth, int argc, VALUE *argv, VALUE (*size_fn)(A
VALUE
rb_enumeratorize_with_size(VALUE obj, VALUE meth, int argc, VALUE *argv, VALUE (*size_fn)(ANYARGS))
{
- return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv, size_fn, Qnil);
+ /* Similar effect as calling obj.to_enum, i.e. dispatching to either
+ Kernel#to_enum vs Lazy#to_enum */
+ if (RTEST(rb_obj_is_kind_of(obj, rb_cLazy)))
+ return lazy_to_enum_i(obj, meth, argc, argv, size_fn);
+ else
+ return enumerator_init(enumerator_allocate(rb_cEnumerator),
+ obj, meth, argc, argv, size_fn, Qnil);
}
static VALUE
@@ -1893,12 +1899,9 @@ lazy_drop_while(VALUE obj)
}
static VALUE
-lazy_cycle(int argc, VALUE *argv, VALUE obj)
+lazy_super(int argc, VALUE *argv, VALUE lazy)
{
- if (rb_block_given_p()) {
- return rb_call_super(argc, argv);
- }
- return lazy_to_enum_i(obj, sym_cycle, argc, argv, rb_enum_cycle_size);
+ return enumerable_lazy(rb_call_super(argc, argv));
}
static VALUE
@@ -2005,8 +2008,9 @@ InitVM_Enumerator(void)
rb_define_method(rb_cLazy, "take_while", lazy_take_while, 0);
rb_define_method(rb_cLazy, "drop", lazy_drop, 1);
rb_define_method(rb_cLazy, "drop_while", lazy_drop_while, 0);
- rb_define_method(rb_cLazy, "cycle", lazy_cycle, -1);
rb_define_method(rb_cLazy, "lazy", lazy_lazy, 0);
+ rb_define_method(rb_cLazy, "chunk", lazy_super, -1);
+ rb_define_method(rb_cLazy, "slice_before", lazy_super, -1);
rb_define_alias(rb_cLazy, "force", "to_a");