summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-07 04:36:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-07 04:36:50 +0000
commit0f2d1527ab1b3b54da2e219ffe3fdd7a741ee1dc (patch)
tree163e771f58ca3a1fcffff23520ab2d5edf0ea284 /enum.c
parente895bc3cdb71eb950951f6a7b7ce70bcb2ae9022 (diff)
* enum.c (DEFINE_ENUMFUNCS): included function signature.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/enum.c b/enum.c
index cab612bbb3..678ae8afb4 100644
--- a/enum.c
+++ b/enum.c
@@ -823,7 +823,11 @@ enum_sort_by(VALUE obj)
return ary;
}
+#define ENUMFUNC(name) rb_block_given_p() ? name##_iter_i : name##_i
+
#define DEFINE_ENUMFUNCS(name) \
+static VALUE enum_##name##_func(VALUE result, VALUE *memo); \
+\
static VALUE \
name##_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \
{ \
@@ -834,10 +838,12 @@ static VALUE \
name##_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \
{ \
return enum_##name##_func(enum_yield(argc, argv), memo); \
-}
+} \
+\
+static VALUE \
+enum_##name##_func(VALUE result, VALUE *memo)
-static VALUE
-enum_all_func(VALUE result, VALUE *memo)
+DEFINE_ENUMFUNCS(all)
{
if (!RTEST(result)) {
*memo = Qfalse;
@@ -846,8 +852,6 @@ enum_all_func(VALUE result, VALUE *memo)
return Qnil;
}
-DEFINE_ENUMFUNCS(all)
-
/*
* call-seq:
* enum.all? [{|obj| block } ] => true or false
@@ -870,12 +874,11 @@ enum_all(VALUE obj)
{
VALUE result = Qtrue;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? all_iter_i : all_i, (VALUE)&result);
+ rb_block_call(obj, id_each, 0, 0, ENUMFUNC(all), (VALUE)&result);
return result;
}
-static VALUE
-enum_any_func(VALUE result, VALUE *memo)
+DEFINE_ENUMFUNCS(any)
{
if (RTEST(result)) {
*memo = Qtrue;
@@ -884,8 +887,6 @@ enum_any_func(VALUE result, VALUE *memo)
return Qnil;
}
-DEFINE_ENUMFUNCS(any)
-
/*
* call-seq:
* enum.any? [{|obj| block } ] => true or false
@@ -909,12 +910,11 @@ enum_any(VALUE obj)
{
VALUE result = Qfalse;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? any_iter_i : any_i, (VALUE)&result);
+ rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any), (VALUE)&result);
return result;
}
-static VALUE
-enum_one_func(VALUE result, VALUE *memo)
+DEFINE_ENUMFUNCS(one)
{
if (RTEST(result)) {
if (*memo == Qundef) {
@@ -928,8 +928,6 @@ enum_one_func(VALUE result, VALUE *memo)
return Qnil;
}
-DEFINE_ENUMFUNCS(one)
-
/*
* call-seq:
* enum.one? [{|obj| block }] => true or false
@@ -953,13 +951,12 @@ enum_one(VALUE obj)
{
VALUE result = Qundef;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? one_iter_i : one_i, (VALUE)&result);
+ rb_block_call(obj, id_each, 0, 0, ENUMFUNC(one), (VALUE)&result);
if (result == Qundef) return Qfalse;
return result;
}
-static VALUE
-enum_none_func(VALUE result, VALUE *memo)
+DEFINE_ENUMFUNCS(none)
{
if (RTEST(result)) {
*memo = Qfalse;
@@ -968,8 +965,6 @@ enum_none_func(VALUE result, VALUE *memo)
return Qnil;
}
-DEFINE_ENUMFUNCS(none)
-
/*
* call-seq:
* enum.none? [{|obj| block }] => true or false
@@ -990,7 +985,7 @@ enum_none(VALUE obj)
{
VALUE result = Qtrue;
- rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? none_iter_i : none_i, (VALUE)&result);
+ rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none), (VALUE)&result);
return result;
}