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

ruby-changes:29629

From: akr <ko1@a...>
Date: Fri, 28 Jun 2013 00:00:02 +0900 (JST)
Subject: [ruby-changes:29629] akr:r41681 (trunk): * bignum.c (abs2twocomp_bang): Removed.

akr	2013-06-27 23:59:50 +0900 (Thu, 27 Jun 2013)

  New Revision: 41681

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

  Log:
    * bignum.c (abs2twocomp_bang): Removed.
      (abs2twocomp): Take n_ret argument to return actual length.
      (rb_big_and): Follow above change.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41680)
+++ ChangeLog	(revision 41681)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jun 27 23:58:13 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (abs2twocomp_bang): Removed.
+	  (abs2twocomp): Take n_ret argument to return actual length.
+	  (rb_big_and): Follow above change.
+
 Thu Jun 27 22:52:19 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (get2comp): Use bary_2comp.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41680)
+++ bignum.c	(revision 41681)
@@ -304,37 +304,24 @@ rb_big_2comp(VALUE x)			/* get 2's compl https://github.com/ruby/ruby/blob/trunk/bignum.c#L304
 }
 
 static BDIGIT
-abs2twocomp_bang(VALUE x)
+abs2twocomp(VALUE *xp, long *n_ret)
 {
-    long numbdigits = RBIGNUM_LEN(x);
-    long n;
+    VALUE x = *xp;
+    long n = RBIGNUM_LEN(x);
     BDIGIT *ds = BDIGITS(x);
-    BDIGIT hibits;
-
-    n = numbdigits;
+    BDIGIT hibits = 0;
 
     while (0 < n && ds[n-1] == 0)
         n--;
 
-    if (n == 0 || RBIGNUM_POSITIVE_P(x))
-        hibits = 0;
-    else {
+    if (n != 0 && RBIGNUM_NEGATIVE_P(x)) {
+        VALUE z = bignew_1(CLASS_OF(x), n, 0);
+        MEMCPY(BDIGITS(z), ds, BDIGIT, n);
+        bary_2comp(BDIGITS(z), n);
         hibits = BDIGMAX;
-        bary_2comp(ds, numbdigits);
-    }
-
-    return hibits;
-}
-
-static BDIGIT
-abs2twocomp(VALUE *xp)
-{
-    VALUE x = *xp;
-    BDIGIT hibits = 0;
-    if (RBIGNUM_NEGATIVE_P(x)) {
-	*xp = x = rb_big_clone(x);
-        hibits = abs2twocomp_bang(x);
+	*xp = z;
     }
+    *n_ret = n;
     return hibits;
 }
 
@@ -4730,27 +4717,29 @@ rb_big_and(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4717
 {
     VALUE z;
     BDIGIT *ds1, *ds2, *zds;
-    long i, l1, l2;
+    long i, xl, yl, l1, l2;
     BDIGIT hibitsx, hibitsy;
     BDIGIT hibits1, hibits2;
     VALUE tmpv;
     BDIGIT tmph;
+    long tmpl;
 
     if (!FIXNUM_P(y) && !RB_TYPE_P(y, T_BIGNUM)) {
 	return rb_num_coerce_bit(x, y, '&');
     }
 
-    hibitsx = abs2twocomp(&x);
+    hibitsx = abs2twocomp(&x, &xl);
     if (FIXNUM_P(y)) {
 	return bigand_int(x, FIX2LONG(y));
     }
-    hibitsy = abs2twocomp(&y);
-    if (RBIGNUM_LEN(x) > RBIGNUM_LEN(y)) {
+    hibitsy = abs2twocomp(&y, &yl);
+    if (xl > yl) {
         tmpv = x; x = y; y = tmpv;
+        tmpl = xl; xl = yl; yl = tmpl;
         tmph = hibitsx; hibitsx = hibitsy; hibitsy = tmph;
     }
-    l1 = RBIGNUM_LEN(x);
-    l2 = RBIGNUM_LEN(y);
+    l1 = xl;
+    l2 = yl;
     ds1 = BDIGITS(x);
     ds2 = BDIGITS(y);
     hibits1 = hibitsx;

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

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