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

ruby-changes:42125

From: naruse <ko1@a...>
Date: Sun, 20 Mar 2016 04:48:45 +0900 (JST)
Subject: [ruby-changes:42125] naruse:r54199 (trunk): * bignum.c (rb_big_cmp): reduce the code.

naruse	2016-03-20 04:48:26 +0900 (Sun, 20 Mar 2016)

  New Revision: 54199

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

  Log:
    * bignum.c (rb_big_cmp): reduce the code.
    
    * bignum.c (rb_big_eq): If normalized bignum is still bignum,
      it must be larger than fixnum.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 54198)
+++ bignum.c	(revision 54199)
@@ -5288,21 +5288,18 @@ rb_integer_float_eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5288
 VALUE
 rb_big_cmp(VALUE x, VALUE y)
 {
-    int cmp;
-
     if (FIXNUM_P(y)) {
-        x = bignorm(x);
+	x = bigfixize(x);
         if (FIXNUM_P(x)) {
-            if (FIX2LONG(x) > FIX2LONG(y)) return INT2FIX(1);
             if (FIX2LONG(x) < FIX2LONG(y)) return INT2FIX(-1);
-            return INT2FIX(0);
-        }
-        else {
-            if (BIGNUM_NEGATIVE_P(x)) return INT2FIX(-1);
-            return INT2FIX(1);
+            return INT2FIX(FIX2LONG(x) > FIX2LONG(y));
         }
     }
     else if (RB_BIGNUM_TYPE_P(y)) {
+	if (BIGNUM_SIGN(x) == BIGNUM_SIGN(y)) {
+	    int cmp = bary_cmp(BDIGITS(x), BIGNUM_LEN(x), BDIGITS(y), BIGNUM_LEN(y));
+	    return INT2FIX(BIGNUM_SIGN(x) ? cmp : -cmp);
+	}
     }
     else if (RB_FLOAT_TYPE_P(y)) {
         return rb_integer_float_cmp(x, y);
@@ -5310,15 +5307,7 @@ rb_big_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5307
     else {
 	return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
     }
-
-    if (BIGNUM_SIGN(x) > BIGNUM_SIGN(y)) return INT2FIX(1);
-    if (BIGNUM_SIGN(x) < BIGNUM_SIGN(y)) return INT2FIX(-1);
-
-    cmp = bary_cmp(BDIGITS(x), BIGNUM_LEN(x), BDIGITS(y), BIGNUM_LEN(y));
-    if (BIGNUM_SIGN(x))
-        return INT2FIX(cmp);
-    else
-        return INT2FIX(-cmp);
+    return INT2FIX(BIGNUM_SIGN(x) ? 1 : -1);
 }
 
 enum big_op_t {
@@ -5434,8 +5423,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/bignum.c#L5423
 rb_big_eq(VALUE x, VALUE y)
 {
     if (FIXNUM_P(y)) {
-	if (bignorm(x) == y) return Qtrue;
-	y = rb_int2big(FIX2LONG(y));
+	return bignorm(x) == y ? Qtrue : Qfalse;
     }
     else if (RB_BIGNUM_TYPE_P(y)) {
     }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54198)
+++ ChangeLog	(revision 54199)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Mar 20 04:46:02 2016  NARUSE, Yui  <naruse@r...>
+
+	* bignum.c (rb_big_cmp): reduce the code.
+
+	* bignum.c (rb_big_eq): If normalized bignum is still bignum,
+	  it must be larger than fixnum.
+
 Sat Mar 20 00:58:00 2016  Kenta Murata  <mrkn@m...>
 
 	* include/ruby/intern.h (rb_big_odd_p, rb_big_even_p): move to

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

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