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

ruby-changes:41758

From: nobu <ko1@a...>
Date: Mon, 15 Feb 2016 14:15:12 +0900 (JST)
Subject: [ruby-changes:41758] nobu:r53832 (trunk): bignum.c: micro optimization

nobu	2016-02-15 14:15:33 +0900 (Mon, 15 Feb 2016)

  New Revision: 53832

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

  Log:
    bignum.c: micro optimization
    
    * bignum.c (rb_big_uminus, bigsub_int): use BIGNUM_NEGATE.
    
    * internal.h (BIGNUM_NEGATE): simplify negation.

  Modified files:
    trunk/bignum.c
    trunk/internal.h
Index: bignum.c
===================================================================
--- bignum.c	(revision 53831)
+++ bignum.c	(revision 53832)
@@ -5526,7 +5526,7 @@ rb_big_uminus(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5526
 {
     VALUE z = rb_big_clone(x);
 
-    BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
+    BIGNUM_NEGATE(z);
 
     return bignorm(z);
 }
@@ -5624,7 +5624,7 @@ bigsub_int(VALUE x, long y0) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5624
     assert(xn == zn);
     num = (BDIGIT_DBL_SIGNED)xds[0] - y;
     if (xn == 1 && num < 0) {
-	BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
+	BIGNUM_NEGATE(z);
 	zds[0] = (BDIGIT)-num;
 	RB_GC_GUARD(x);
 	return bignorm(z);
@@ -5687,7 +5687,7 @@ bigsub_int(VALUE x, long y0) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5687
     assert(num == 0 || num == -1);
     if (num < 0) {
         get2comp(z);
-	BIGNUM_SET_SIGN(z, !BIGNUM_SIGN(x));
+	BIGNUM_NEGATE(z);
     }
     RB_GC_GUARD(x);
     return bignorm(z);
Index: internal.h
===================================================================
--- internal.h	(revision 53831)
+++ internal.h	(revision 53832)
@@ -364,6 +364,7 @@ struct RBignum { https://github.com/ruby/ruby/blob/trunk/internal.h#L364
           : (RBASIC(b)->flags &= ~BIGNUM_SIGN_BIT))
 #define BIGNUM_POSITIVE_P(b) BIGNUM_SIGN(b)
 #define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b))
+#define BIGNUM_NEGATE(b) (RBASIC(b)->flags ^= BIGNUM_SIGN_BIT)
 
 #define BIGNUM_EMBED_FLAG FL_USER2
 #define BIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)

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

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