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

ruby-changes:4395

From: ko1@a...
Date: Wed, 2 Apr 2008 22:31:58 +0900 (JST)
Subject: [ruby-changes:4395] matz - Ruby:r15886 (trunk): * rational.c (nurat_int_check): function for DRY integer check.

matz	2008-04-02 22:31:42 +0900 (Wed, 02 Apr 2008)

  New Revision: 15886

  Modified files:
    trunk/ChangeLog
    trunk/rational.c
    trunk/version.h

  Log:
    * rational.c (nurat_int_check): function for DRY integer check.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=15886&r2=15885&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15886&r2=15885&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/rational.c?r1=15886&r2=15885&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15885)
+++ ChangeLog	(revision 15886)
@@ -1,3 +1,7 @@
+Wed Apr  2 22:29:35 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* rational.c (nurat_int_check): function for DRY integer check.
+
 Wed Apr  2 06:52:31 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* .gdbinit (rp): supports rational and complex numbers.  it's
Index: version.h
===================================================================
--- version.h	(revision 15885)
+++ version.h	(revision 15886)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.9.0"
-#define RUBY_RELEASE_DATE "2008-04-01"
+#define RUBY_RELEASE_DATE "2008-04-02"
 #define RUBY_VERSION_CODE 190
-#define RUBY_RELEASE_CODE 20080401
+#define RUBY_RELEASE_CODE 20080402
 #define RUBY_PATCHLEVEL 0
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 0
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 4
-#define RUBY_RELEASE_DAY 1
+#define RUBY_RELEASE_DAY 2
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: rational.c
===================================================================
--- rational.c	(revision 15885)
+++ rational.c	(revision 15886)
@@ -427,6 +427,18 @@
 
 #define f_unify_p(klass) rb_const_defined(klass, id_Unify)
 
+static inline void
+nurat_int_check(VALUE num)
+{
+    switch (TYPE(num)) {
+      case T_FIXNUM:
+      case T_BIGNUM:
+	break;
+      default:
+	rb_raise(rb_eArgError, "not an integer");
+    }
+}
+
 inline static VALUE
 nurat_s_canonicalize_internal(VALUE klass, VALUE num, VALUE den)
 {
@@ -487,22 +499,9 @@
 	break;
     }
 
-    switch (TYPE(num)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	break;
-      default:
-	rb_raise(rb_eArgError, "not an integer");
-    }
+    nurat_int_check(num);
+    nurat_int_check(den);
 
-    switch (TYPE(den)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	break;
-      default:
-	rb_raise(rb_eArgError, "not an integer");
-    }
-
     return nurat_s_canonicalize_internal(klass, num, den);
 }
 #endif
@@ -518,22 +517,9 @@
 	break;
     }
 
-    switch (TYPE(num)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	break;
-      default:
-	rb_raise(rb_eArgError, "not an integer");
-    }
+    nurat_int_check(num);
+    nurat_int_check(den);
 
-    switch (TYPE(den)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	break;
-      default:
-	rb_raise(rb_eArgError, "not an integer");
-    }
-
     return nurat_s_canonicalize_internal(klass, num, den);
 }
 
@@ -1223,42 +1209,21 @@
 VALUE
 rb_gcd(VALUE self, VALUE other)
 {
-    switch (TYPE(other)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	break;
-      default:
-	rb_raise(rb_eArgError, "not an integer");
-    }
-
+    nurat_int_check(other);
     return f_gcd(self, other);
 }
 
 VALUE
 rb_lcm(VALUE self, VALUE other)
 {
-    switch (TYPE(other)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	break;
-      default:
-	rb_raise(rb_eArgError, "not an integer");
-    }
-
+    nurat_int_check(other);
     return f_lcm(self, other);
 }
 
 VALUE
 rb_gcdlcm(VALUE self, VALUE other)
 {
-    switch (TYPE(other)) {
-      case T_FIXNUM:
-      case T_BIGNUM:
-	break;
-      default:
-	rb_raise(rb_eArgError, "not an integer");
-    }
-
+    nurat_int_check(other);
     return rb_assoc_new(f_gcd(self, other), f_lcm(self, other));
 }
 

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

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