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

ruby-changes:32833

From: akr <ko1@a...>
Date: Wed, 12 Feb 2014 03:20:51 +0900 (JST)
Subject: [ruby-changes:32833] akr:r44910 (trunk): * bignum.c (rb_big_cmp): Specialize a comparison to zero.

akr	2014-02-11 23:43:23 +0900 (Tue, 11 Feb 2014)

  New Revision: 44910

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44910

  Log:
    * bignum.c (rb_big_cmp): Specialize a comparison to zero.
    
    * ext/bigdecimal/bigdecimal.c (is_negative): Use rb_big_cmp instead of
      RBIGNUM_NEGATIVE_P.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/ext/bigdecimal/bigdecimal.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44909)
+++ ChangeLog	(revision 44910)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Feb 11 23:42:27 2014  Tanaka Akira  <akr@f...>
+
+	* bignum.c (rb_big_cmp): Specialize a comparison to zero.
+
+	* ext/bigdecimal/bigdecimal.c (is_negative): Use rb_big_cmp instead of
+	  RBIGNUM_NEGATIVE_P.
+
 Tue Feb 11 22:59:10 2014  Tanaka Akira  <akr@f...>
 
 	* ext/openssl/ossl_bn.c (ossl_bn_initialize): Use rb_integer_pack.
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 44909)
+++ ext/bigdecimal/bigdecimal.c	(revision 44910)
@@ -2095,7 +2095,7 @@ is_negative(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2095
 	return FIX2LONG(x) < 0;
     }
     else if (RB_TYPE_P(x, T_BIGNUM)) {
-	return RBIGNUM_NEGATIVE_P(x);
+	return FIX2INT(rb_big_cmp(x, INT2FIX(0))) < 0;
     }
     else if (RB_TYPE_P(x, T_FLOAT)) {
 	return RFLOAT_VALUE(x) < 0.0;
Index: bignum.c
===================================================================
--- bignum.c	(revision 44909)
+++ bignum.c	(revision 44910)
@@ -5395,7 +5395,12 @@ rb_big_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5395
 {
     int cmp;
 
-    if (FIXNUM_P(y)) {
+    if (y == INT2FIX(0)) {
+        if (BIGZEROP(x)) return INT2FIX(0);
+        if (RBIGNUM_NEGATIVE_P(x)) return INT2FIX(-1);
+        return INT2FIX(1);
+    }
+    else if (FIXNUM_P(y)) {
 	y = rb_int2big(FIX2LONG(y));
     }
     else if (RB_BIGNUM_TYPE_P(y)) {

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

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