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

ruby-changes:44435

From: nobu <ko1@a...>
Date: Fri, 28 Oct 2016 15:19:08 +0900 (JST)
Subject: [ruby-changes:44435] nobu:r56507 (trunk): complex.c: FINITE_TYPE_P

nobu	2016-10-28 15:19:00 +0900 (Fri, 28 Oct 2016)

  New Revision: 56507

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56507

  Log:
    complex.c: FINITE_TYPE_P
    
    * complex.c (FINITE_TYPE_P): extract predicate.
    * complex.c (rb_complex_finite_p, rb_complex_infinite_p): use
      dedicated predicates instead of switch by TYPE.

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
Index: complex.c
===================================================================
--- complex.c	(revision 56506)
+++ complex.c	(revision 56507)
@@ -1331,6 +1331,8 @@ nucomp_inspect(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1331
     return s;
 }
 
+#define FINITE_TYPE_P(v) (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL))
+
 /*
  * call-seq:
  *    cmp.finite?  ->  true or false
@@ -1342,17 +1344,15 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L1344
 rb_complex_finite_p(VALUE self)
 {
     VALUE magnitude = nucomp_abs(self);
-    double f;
 
-    switch (TYPE(magnitude)) {
-    case T_FIXNUM: case T_BIGNUM: case T_RATIONAL:
+    if (FINITE_TYPE_P(magnitude)) {
 	return Qtrue;
-
-    case T_FLOAT:
-	f = RFLOAT_VALUE(magnitude);
+    }
+    else if (RB_FLOAT_TYPE_P(magnitude)) {
+	const double f = RFLOAT_VALUE(magnitude);
 	return isinf(f) ? Qfalse : Qtrue;
-
-    default:
+    }
+    else {
 	return rb_funcall(magnitude, rb_intern("finite?"), 0);
     }
 }
@@ -1375,20 +1375,18 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L1375
 rb_complex_infinite_p(VALUE self)
 {
     VALUE magnitude = nucomp_abs(self);
-    double f;
 
-    switch (TYPE(magnitude)) {
-    case T_FIXNUM: case T_BIGNUM: case T_RATIONAL:
+    if (FINITE_TYPE_P(magnitude)) {
 	return Qnil;
-
-    case T_FLOAT:
-	f = RFLOAT_VALUE(magnitude);
+    }
+    if (RB_FLOAT_TYPE_P(magnitude)) {
+	const double f = RFLOAT_VALUE(magnitude);
 	if (isinf(f)) {
 	    return INT2FIX(f < 0 ? -1 : 1);
 	}
 	return Qnil;
-
-    default:
+    }
+    else {
 	return rb_funcall(magnitude, rb_intern("infinite?"), 0);
     }
 }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56506)
+++ ChangeLog	(revision 56507)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 28 15:18:58 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* complex.c (FINITE_TYPE_P): extract predicate.
+
+	* complex.c (rb_complex_finite_p, rb_complex_infinite_p): use
+	  dedicated predicates instead of switch by TYPE.
+
 Thu Oct 27 23:28:12 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (rb_integer_type_p): turn into macro to help

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

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