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

ruby-changes:50558

From: nobu <ko1@a...>
Date: Fri, 9 Mar 2018 11:06:44 +0900 (JST)
Subject: [ruby-changes:50558] nobu:r62701 (trunk): complex.c: removed redundant conditions

nobu	2018-03-09 11:06:39 +0900 (Fri, 09 Mar 2018)

  New Revision: 62701

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

  Log:
    complex.c: removed redundant conditions
    
    Fixnums can be compared by object values themselves only.
    Addition/subtraction/mulplication of fixnum 0 do not affect the
    sign.

  Modified files:
    trunk/complex.c
Index: complex.c
===================================================================
--- complex.c	(revision 62700)
+++ complex.c	(revision 62701)
@@ -70,12 +70,10 @@ f_##n(VALUE x, VALUE y)\ https://github.com/ruby/ruby/blob/trunk/complex.c#L70
 inline static VALUE
 f_add(VALUE x, VALUE y)
 {
-#ifndef PRESERVE_SIGNEDZERO
-    if (FIXNUM_P(y) && FIXNUM_ZERO_P(y))
+    if (FIXNUM_ZERO_P(y))
 	return x;
-    else if (FIXNUM_P(x) && FIXNUM_ZERO_P(x))
+    if (FIXNUM_ZERO_P(x))
 	return y;
-#endif
     return rb_funcall(x, '+', 1, y);
 }
 
@@ -107,36 +105,20 @@ f_gt_p(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/complex.c#L105
 inline static VALUE
 f_mul(VALUE x, VALUE y)
 {
-#ifndef PRESERVE_SIGNEDZERO
-    if (FIXNUM_P(y)) {
-	long iy = FIX2LONG(y);
-	if (iy == 0) {
-	    if (RB_INTEGER_TYPE_P(x))
-		return ZERO;
-	}
-	else if (iy == 1)
-	    return x;
-    }
-    else if (FIXNUM_P(x)) {
-	long ix = FIX2LONG(x);
-	if (ix == 0) {
-	    if (RB_INTEGER_TYPE_P(y))
-		return ZERO;
-	}
-	else if (ix == 1)
-	    return y;
-    }
-#endif
+    if (FIXNUM_ZERO_P(y) && RB_INTEGER_TYPE_P(x))
+	return ZERO;
+    if (FIXNUM_ZERO_P(x) && RB_INTEGER_TYPE_P(y))
+	return ZERO;
+    if (y == ONE) return x;
+    if (x == ONE) return y;
     return rb_funcall(x, '*', 1, y);
 }
 
 inline static VALUE
 f_sub(VALUE x, VALUE y)
 {
-#ifndef PRESERVE_SIGNEDZERO
-    if (FIXNUM_P(y) && FIXNUM_ZERO_P(y))
+    if (FIXNUM_ZERO_P(y))
 	return x;
-#endif
     return rb_funcall(x, '-', 1, y);
 }
 

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

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