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

ruby-changes:42128

From: nobu <ko1@a...>
Date: Sun, 20 Mar 2016 19:09:19 +0900 (JST)
Subject: [ruby-changes:42128] nobu:r54202 (trunk): bignum.c: micro optimization

nobu	2016-03-20 19:09:14 +0900 (Sun, 20 Mar 2016)

  New Revision: 54202

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

  Log:
    bignum.c: micro optimization
    
    * bignum.c (rb_big_cmp): micro optimization of Fixnum comparison.
      as SIGNED_VALUE and Fixnum have same sign-bits and same order.

  Modified files:
    trunk/bignum.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 54201)
+++ bignum.c	(revision 54202)
@@ -5291,8 +5291,11 @@ rb_big_cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5291
     if (FIXNUM_P(y)) {
 	x = bigfixize(x);
         if (FIXNUM_P(x)) {
-            if (FIX2LONG(x) < FIX2LONG(y)) return INT2FIX(-1);
-            return INT2FIX(FIX2LONG(x) > FIX2LONG(y));
+	    /* SIGNED_VALUE and Fixnum have same sign-bits, same
+	     * order */
+	    SIGNED_VALUE sx = (SIGNED_VALUE)x, sy = (SIGNED_VALUE)y;
+	    if (sx < sy) return INT2FIX(-1);
+	    return INT2FIX(sx > sy);
         }
     }
     else if (RB_BIGNUM_TYPE_P(y)) {

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

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