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

ruby-changes:32886

From: akr <ko1@a...>
Date: Sat, 15 Feb 2014 11:48:48 +0900 (JST)
Subject: [ruby-changes:32886] akr:r44965 (trunk): * bignum.c (rb_big_cmp): Avoid bignum allocation for comparison

akr	2014-02-15 11:48:44 +0900 (Sat, 15 Feb 2014)

  New Revision: 44965

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

  Log:
    * bignum.c (rb_big_cmp): Avoid bignum allocation for comparison
      between bignum and fixnum.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44964)
+++ ChangeLog	(revision 44965)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Feb 15 11:47:47 2014  Tanaka Akira  <akr@f...>
+
+	* bignum.c (rb_big_cmp): Avoid bignum allocation for comparison
+	  between bignum and fixnum.
+
 Sat Feb 15 10:55:12 2014  Hiroshi Shirosaki  <h.shirosaki@g...>
 
 	* ext/-test-/win32/fd_setsize/depend: fix wrong dependencies.
Index: bignum.c
===================================================================
--- bignum.c	(revision 44964)
+++ bignum.c	(revision 44965)
@@ -5277,13 +5277,17 @@ rb_big_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5277
 {
     int cmp;
 
-    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));
+    if (FIXNUM_P(y)) {
+        x = bignorm(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 (RBIGNUM_NEGATIVE_P(x)) return INT2FIX(-1);
+            return INT2FIX(1);
+        }
     }
     else if (RB_BIGNUM_TYPE_P(y)) {
     }

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

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