From 0f2d1527ab1b3b54da2e219ffe3fdd7a741ee1dc Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 7 Jul 2009 04:36:50 +0000 Subject: * enum.c (DEFINE_ENUMFUNCS): included function signature. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 +++- enum.c | 37 ++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b4396f744..277863bbe2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ -Tue Jul 7 13:34:30 2009 Nobuyoshi Nakada +Tue Jul 7 13:36:46 2009 Nobuyoshi Nakada + + * enum.c (DEFINE_ENUMFUNCS): included function signature. * enum.c (rb_enum_join): non-nil separator must be convertible to String. [ruby-core:24172] 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; } -- cgit v1.2.3