summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-02-03 09:15:42 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-02-03 09:15:42 +0000
commit5675cdbd418509bdb1abbc4442a681b808ed35e8 (patch)
treed731ff563b61a1983f234474bb3f72d190e8f91f /enumerator.c
parente4f1feac3e807e2e3790237749cfdb7a6104fd90 (diff)
* eval.c: unify ruby_class (for method definition) and ruby_cbase
(for constant reference). * eval.c (rb_call0): use TMP_ALLOC() instead of allocating a temporary array object. * eval.c (eval): need not to protect $SAFE value. [ruby-core:07177] * error.c (Init_Exception): change NameError to direct subclass of Exception so that default rescue do not handle it silently. * struct.c (rb_struct_select): update RDoc description. [ruby-core:7254] * numeric.c (int_upto): return an enumerator if no block is attached to the method. * numeric.c (int_downto): ditto. * numeric.c (int_dotimes): ditto. * enum.c (enum_first): new method Enumerable#first to take first n element from an enumerable. * enum.c (enum_group_by): new method Enumerable#group_by that groups enumerable values according to their block values. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/enumerator.c b/enumerator.c
index 7b3af9f66b..3321e71dbe 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -32,18 +32,6 @@ proc_call(VALUE proc, VALUE args)
return rb_proc_call(proc, args);
}
-static VALUE
-method_call(VALUE method, VALUE args)
-{
- int argc = 0;
- VALUE *argv = 0;
- if (args) {
- argc = RARRAY(args)->len;
- argv = RARRAY(args)->ptr;
- }
- return rb_method_call(argc, argv, method);
-}
-
struct enumerator {
VALUE method;
VALUE proc;
@@ -168,7 +156,7 @@ enum_each_slice(VALUE obj, VALUE n)
args[0] = rb_ary_new2(size);
args[1] = (VALUE)size;
- rb_iterate(rb_each, obj, each_slice_i, (VALUE)args);
+ rb_block_call(obj, rb_intern("each"), 0, 0, each_slice_i, (VALUE)args);
ary = args[0];
if (RARRAY(ary)->len > 0) rb_yield(ary);
@@ -235,7 +223,7 @@ enum_each_cons(VALUE obj, VALUE n)
args[0] = rb_ary_new2(size);
args[1] = (VALUE)size;
- rb_iterate(rb_each, obj, each_cons_i, (VALUE)args);
+ rb_block_call(obj, rb_intern("each"), 0, 0, each_cons_i, (VALUE)args);
return Qnil;
}
@@ -315,14 +303,6 @@ rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv);
}
-static VALUE
-enumerator_iter(VALUE memo)
-{
- struct enumerator *e = (struct enumerator *)memo;
-
- return method_call(e->method, e->args);
-}
-
/*
* call-seq:
* enum.each {...}
@@ -335,8 +315,14 @@ static VALUE
enumerator_each(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
+ int argc = 0;
+ VALUE *argv = 0;
- return rb_iterate(enumerator_iter, (VALUE)e, e->iter, (VALUE)e);
+ if (e->args) {
+ argc = RARRAY(e->args)->len;
+ argv = RARRAY(e->args)->ptr;
+ }
+ return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
}
static VALUE
@@ -360,9 +346,17 @@ enumerator_with_index(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE memo = 0;
+ int argc = 0;
+ VALUE *argv = 0;
+
+ if (e->args) {
+ argc = RARRAY(e->args)->len;
+ argv = RARRAY(e->args)->ptr;
+ }
+ return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
- return rb_iterate(enumerator_iter, (VALUE)e,
- enumerator_with_index_i, (VALUE)&memo);
+ return rb_block_call(e->method, rb_intern("call"), argc, argv,
+ enumerator_with_index_i, (VALUE)&memo);
}
void