[前][次][番号順一覧][スレッド一覧]

ruby-changes:4911

From: ko1@a...
Date: Tue, 13 May 2008 23:33:10 +0900 (JST)
Subject: [ruby-changes:4911] nobu - Ruby:r16404 (trunk): * enum.c (enum_yield): use rb_yield_values2.

nobu	2008-05-13 23:32:46 +0900 (Tue, 13 May 2008)

  New Revision: 16404

  Modified files:
    trunk/ChangeLog
    trunk/enum.c

  Log:
    * 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.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16404&r2=16403&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/enum.c?r1=16404&r2=16403&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16403)
+++ ChangeLog	(revision 16404)
@@ -1,3 +1,13 @@
+Tue May 13 23:32:44 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@i...>
 
 	* enumerator.c: Update rdoc.
Index: enum.c
===================================================================
--- enum.c	(revision 16403)
+++ enum.c	(revision 16404)
@@ -28,11 +28,7 @@
     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 @@
     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 @@
 }
 
 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 @@
 }
 
 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 @@
     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 @@
 }
 
 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:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]