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

ruby-changes:29646

From: akr <ko1@a...>
Date: Sun, 30 Jun 2013 01:59:17 +0900 (JST)
Subject: [ruby-changes:29646] akr:r41698 (trunk): * bignum.c (big_rshift): Use abs2twocomp and twocomp2abs_bang.

akr	2013-06-30 01:58:58 +0900 (Sun, 30 Jun 2013)

  New Revision: 41698

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

  Log:
    * bignum.c (big_rshift): Use abs2twocomp and twocomp2abs_bang.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41697)
+++ ChangeLog	(revision 41698)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun 30 01:57:08 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (big_rshift): Use abs2twocomp and twocomp2abs_bang.
+
 Sun Jun 30 00:14:20 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (RBIGNUM_SET_NEGATIVE_SIGN): New macro.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41697)
+++ bignum.c	(revision 41698)
@@ -5163,33 +5163,28 @@ big_rshift(VALUE x, unsigned long shift) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5163
     long s1 = shift/BITSPERDIG;
     int s2 = (int)(shift%BITSPERDIG);
     VALUE z;
-    long i, j;
-    volatile VALUE save_x;
+    long j;
+    long xl;
+    BDIGIT hibitsx;
 
     if (s1 > RBIGNUM_LEN(x)) {
-	if (RBIGNUM_SIGN(x))
+	if (RBIGNUM_POSITIVE_P(x) || bary_zero_p(BDIGITS(x), RBIGNUM_LEN(x)))
 	    return INT2FIX(0);
 	else
 	    return INT2FIX(-1);
     }
-    if (!RBIGNUM_SIGN(x)) {
-	x = rb_big_clone(x);
-	get2comp(x);
-    }
-    save_x = x;
+    hibitsx = abs2twocomp(&x, &xl);
     xds = BDIGITS(x);
-    i = RBIGNUM_LEN(x); j = i - s1;
-    if (j == 0) {
-	if (RBIGNUM_SIGN(x)) return INT2FIX(0);
+    j = xl - s1;
+    if (j <= 0) {
+	if (!hibitsx) return INT2FIX(0);
 	else return INT2FIX(-1);
     }
-    z = bignew(j, RBIGNUM_SIGN(x));
+    z = bignew(j, 0);
     zds = BDIGITS(z);
-    bary_small_rshift(zds, xds+s1, j, s2, !RBIGNUM_SIGN(x));
-    if (!RBIGNUM_SIGN(x)) {
-	get2comp(z);
-    }
-    RB_GC_GUARD(save_x);
+    bary_small_rshift(zds, xds+s1, j, s2, hibitsx != 0);
+    twocomp2abs_bang(z, hibitsx != 0);
+    RB_GC_GUARD(x);
     return z;
 }
 

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

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