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

ruby-changes:44689

From: mrkn <ko1@a...>
Date: Sun, 13 Nov 2016 03:42:34 +0900 (JST)
Subject: [ruby-changes:44689] mrkn:r56762 (trunk): complex.c: refactoring

mrkn	2016-11-13 03:42:30 +0900 (Sun, 13 Nov 2016)

  New Revision: 56762

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

  Log:
    complex.c: refactoring
    
    * complex.c: refactor to use some specific macros and
      to reduce needless conversion by FIX2LONG.
    
    * complex.c (k_fixnum_p, k_bignum_p): removed.

  Modified files:
    trunk/complex.c
Index: complex.c
===================================================================
--- complex.c	(revision 56761)
+++ complex.c	(revision 56762)
@@ -81,9 +81,9 @@ inline static VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L81
 f_add(VALUE x, VALUE y)
 {
 #ifndef PRESERVE_SIGNEDZERO
-    if (FIXNUM_P(y) && FIX2LONG(y) == 0)
+    if (FIXNUM_P(y) && FIXNUM_ZERO_P(y))
 	return x;
-    else if (FIXNUM_P(x) && FIX2LONG(x) == 0)
+    else if (FIXNUM_P(x) && FIXNUM_ZERO_P(x))
 	return y;
 #endif
     return rb_funcall(x, '+', 1, y);
@@ -135,7 +135,7 @@ inline static VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L135
 f_sub(VALUE x, VALUE y)
 {
 #ifndef PRESERVE_SIGNEDZERO
-    if (FIXNUM_P(y) && FIX2LONG(y) == 0)
+    if (FIXNUM_P(y) && FIXNUM_ZERO_P(y))
 	return x;
 #endif
     return rb_funcall(x, '-', 1, y);
@@ -169,7 +169,7 @@ inline static VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L169
 f_eqeq_p(VALUE x, VALUE y)
 {
     if (FIXNUM_P(x) && FIXNUM_P(y))
-	return f_boolcast(FIX2LONG(x) == FIX2LONG(y));
+	return f_boolcast(x == y);
     return rb_funcall(x, id_eqeq_p, 1, y);
 }
 
@@ -181,7 +181,7 @@ inline static VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L181
 f_negative_p(VALUE x)
 {
     if (FIXNUM_P(x))
-	return f_boolcast(FIX2LONG(x) < 0);
+	return f_boolcast(FIXNUM_NEGATIVE_P(x));
     return rb_funcall(x, '<', 1, ZERO);
 }
 
@@ -190,8 +190,8 @@ f_negative_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L190
 inline static VALUE
 f_zero_p(VALUE x)
 {
-    if (RB_TYPE_P(x, T_FIXNUM)) {
-	return f_boolcast(FIX2LONG(x) == 0);
+    if (FIXNUM_P(x)) {
+	return f_boolcast(FIXNUM_ZERO_P(x));
     }
     else if (RB_TYPE_P(x, T_BIGNUM)) {
 	return Qfalse;
@@ -199,7 +199,7 @@ f_zero_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L199
     else if (RB_TYPE_P(x, T_RATIONAL)) {
 	VALUE num = RRATIONAL(x)->num;
 
-	return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 0);
+	return f_boolcast(FIXNUM_P(num) && FIXNUM_ZERO_P(num));
     }
     return rb_funcall(x, id_eqeq_p, 1, ZERO);
 }
@@ -209,7 +209,7 @@ f_zero_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L209
 inline static VALUE
 f_one_p(VALUE x)
 {
-    if (RB_TYPE_P(x, T_FIXNUM)) {
+    if (FIXNUM_P(x)) {
 	return f_boolcast(FIX2LONG(x) == 1);
     }
     else if (RB_TYPE_P(x, T_BIGNUM)) {
@@ -238,18 +238,6 @@ k_numeric_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L238
 }
 
 inline static VALUE
-k_fixnum_p(VALUE x)
-{
-    return FIXNUM_P(x);
-}
-
-inline static VALUE
-k_bignum_p(VALUE x)
-{
-    return RB_TYPE_P(x, T_BIGNUM);
-}
-
-inline static VALUE
 k_float_p(VALUE x)
 {
     return f_kind_of_p(x, rb_cFloat);
@@ -352,9 +340,8 @@ nucomp_canonicalization(int f) https://github.com/ruby/ruby/blob/trunk/complex.c#L340
 inline static void
 nucomp_real_check(VALUE num)
 {
-    if (!RB_TYPE_P(num, T_FIXNUM) &&
-	!RB_TYPE_P(num, T_BIGNUM) &&
-	!RB_TYPE_P(num, T_FLOAT) &&
+    if (!RB_INTEGER_TYPE_P(num) &&
+	!RB_FLOAT_TYPE_P(num) &&
 	!RB_TYPE_P(num, T_RATIONAL)) {
 	if (!k_numeric_p(num) || !f_real_p(num))
 	    rb_raise(rb_eTypeError, "not a real");
@@ -936,7 +923,7 @@ nucomp_expt(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/complex.c#L923
 		       f_mul(dat->imag, m_log_bang(r)));
 	return f_complex_polar(CLASS_OF(self), nr, ntheta);
     }
-    if (k_fixnum_p(other)) {
+    if (FIXNUM_P(other)) {
 	if (f_gt_p(other, ZERO)) {
 	    VALUE x, z;
 	    long n;
@@ -973,7 +960,7 @@ nucomp_expt(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/complex.c#L960
     if (k_numeric_p(other) && f_real_p(other)) {
 	VALUE r, theta;
 
-	if (k_bignum_p(other))
+	if (RB_TYPE_P(other, T_BIGNUM))
 	    rb_warn("in a**b, b may be too big");
 
 	r = f_abs(self);
@@ -1258,7 +1245,7 @@ nucomp_eql_p(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/complex.c#L1245
 inline static VALUE
 f_signbit(VALUE x)
 {
-    if (RB_TYPE_P(x, T_FLOAT)) {
+    if (RB_FLOAT_TYPE_P(x)) {
 	double f = RFLOAT_VALUE(x);
 	return f_boolcast(!isnan(f) && signbit(f));
     }

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

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