summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-13 14:32:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-13 14:32:46 +0000
commit1072cb65c996e672b23878839fac27c47d722f73 (patch)
tree69aeb0eb0b52c201b5f11e21404739a6b4e19189
parent74430e8679e193c515ee5bdf8e5e3eeb504327e2 (diff)
* enum.c (enum_yield): use rb_yield_values2.
* enum.c (DEFINE_ENUMFUNCS): macro to define enumerator and yielding functions. * enum.c (enum_all_func, enum_any_func, enum_one_func, enum_none_func): reduced duplicate code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--enum.c80
2 files changed, 36 insertions, 54 deletions
diff --git a/ChangeLog b/ChangeLog
index fd4c27c..f114e95 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue May 13 23:32:44 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * enum.c (enum_yield): use rb_yield_values2.
+
+ * enum.c (DEFINE_ENUMFUNCS): macro to define enumerator and yielding
+ functions.
+
+ * enum.c (enum_all_func, enum_any_func, enum_one_func,
+ enum_none_func): reduced duplicate code.
+
Tue May 13 15:09:38 2008 Akinori MUSHA <knu@iDaemons.org>
* enumerator.c: Update rdoc.
diff --git a/enum.c b/enum.c
index a485a72..a7821e8 100644
--- a/enum.c
+++ b/enum.c
@@ -28,11 +28,7 @@ enum_values_pack(int argc, VALUE *argv)
i = enum_values_pack(argc, argv); \
} while (0)
-static VALUE
-enum_yield(int argc, VALUE *argv)
-{
- return rb_yield(enum_values_pack(argc, argv));
-}
+#define enum_yield rb_yield_values2
static VALUE
grep_i(VALUE i, VALUE *arg, int argc, VALUE *argv)
@@ -791,26 +787,31 @@ enum_sort_by(VALUE obj)
return ary;
}
-static VALUE
-all_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
-{
- if (!RTEST(enum_values_pack(argc, argv))) {
- *memo = Qfalse;
- rb_iter_break();
- }
- return Qnil;
+#define DEFINE_ENUMFUNCS(name) \
+static VALUE \
+name##_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \
+{ \
+ return enum_##name##_func(enum_values_pack(argc, argv), memo); \
+} \
+\
+static VALUE \
+name##_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv) \
+{ \
+ return enum_##name##_func(enum_yield(argc, argv), memo); \
}
-
+
static VALUE
-all_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
+enum_all_func(VALUE result, VALUE *memo)
{
- if (!RTEST(enum_yield(argc, argv))) {
+ if (!RTEST(result)) {
*memo = Qfalse;
rb_iter_break();
}
return Qnil;
}
+DEFINE_ENUMFUNCS(all)
+
/*
* call-seq:
* enum.all? [{|obj| block } ] => true or false
@@ -838,24 +839,16 @@ enum_all(VALUE obj)
}
static VALUE
-any_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
+enum_any_func(VALUE result, VALUE *memo)
{
- if (RTEST(enum_values_pack(argc, argv))) {
+ if (RTEST(result)) {
*memo = Qtrue;
rb_iter_break();
}
return Qnil;
}
-static VALUE
-any_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
-{
- if (RTEST(enum_yield(argc, argv))) {
- *memo = Qtrue;
- rb_iter_break();
- }
- return Qnil;
-}
+DEFINE_ENUMFUNCS(any)
/*
* call-seq:
@@ -885,9 +878,9 @@ enum_any(VALUE obj)
}
static VALUE
-one_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
+enum_one_func(VALUE result, VALUE *memo)
{
- if (RTEST(enum_values_pack(argc, argv))) {
+ if (RTEST(result)) {
if (*memo == Qundef) {
*memo = Qtrue;
}
@@ -899,20 +892,7 @@ one_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
return Qnil;
}
-static VALUE
-one_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
-{
- if (RTEST(enum_yield(argc, argv))) {
- if (*memo == Qundef) {
- *memo = Qtrue;
- }
- else if (*memo == Qtrue) {
- *memo = Qfalse;
- rb_iter_break();
- }
- }
- return Qnil;
-}
+DEFINE_ENUMFUNCS(one)
/*
* call-seq:
@@ -943,24 +923,16 @@ enum_one(VALUE obj)
}
static VALUE
-none_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
+enum_none_func(VALUE result, VALUE *memo)
{
- if (RTEST(enum_values_pack(argc, argv))) {
+ if (RTEST(result)) {
*memo = Qfalse;
rb_iter_break();
}
return Qnil;
}
-static VALUE
-none_iter_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
-{
- if (RTEST(enum_yield(argc, argv))) {
- *memo = Qfalse;
- rb_iter_break();
- }
- return Qnil;
-}
+DEFINE_ENUMFUNCS(none)
/*
* call-seq: