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

ruby-changes:29527

From: akr <ko1@a...>
Date: Sun, 23 Jun 2013 01:29:54 +0900 (JST)
Subject: [ruby-changes:29527] akr:r41579 (trunk): * bignum.c (bytes_zero_p): Removed.

akr	2013-06-23 01:29:43 +0900 (Sun, 23 Jun 2013)

  New Revision: 41579

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

  Log:
    * bignum.c (bytes_zero_p): Removed.
      (bary_pack): Don't call bytes_zero_p.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41578)
+++ ChangeLog	(revision 41579)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun 23 01:27:54 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (bytes_zero_p): Removed.
+	  (bary_pack): Don't call bytes_zero_p.
+
 Sun Jun 23 00:51:29 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (bytes_zero_p): Extracted from bary_pack.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41578)
+++ bignum.c	(revision 41579)
@@ -124,15 +124,6 @@ rb_big_dump(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L124
 #endif
 
 static int
-bytes_zero_p(unsigned char *p, size_t n)
-{
-    while (n--)
-        if (*p++)
-            return 0;
-    return 1;
-}
-
-static int
 bary_zero_p(BDIGIT *xds, size_t nx)
 {
     if (nx == 0)
@@ -922,7 +913,7 @@ bary_pack(int sign, BDIGIT *ds, size_t n https://github.com/ruby/ruby/blob/trunk/bignum.c#L913
         if (nails == 0 && SIZEOF_BDIGITS == sizeof(BDIGIT) &&
             (flags & INTEGER_PACK_WORDORDER_MASK) == INTEGER_PACK_LSWORD_FIRST &&
             (flags & INTEGER_PACK_BYTEORDER_MASK) != INTEGER_PACK_MSBYTE_FIRST) {
-            size_t src_size = num_bdigits * SIZEOF_BDIGITS;
+            size_t src_size = (de - dp) * SIZEOF_BDIGITS;
             size_t dst_size = numwords * wordsize;
             int overflow = 0;
             while (0 < src_size && ((unsigned char *)ds)[src_size-1] == 0)
@@ -939,9 +930,8 @@ bary_pack(int sign, BDIGIT *ds, size_t n https://github.com/ruby/ruby/blob/trunk/bignum.c#L930
                 int zero_p = bytes_2comp(words, dst_size);
                 if (zero_p && overflow) {
                     unsigned char *p = (unsigned char *)dp;
-                    if (dst_size < src_size &&
-                        p[dst_size] == 1 &&
-                        bytes_zero_p(p+dst_size+1, src_size-dst_size-1)) {
+                    if (dst_size == src_size-1 &&
+                        p[dst_size] == 1) {
                         overflow = 0;
                     }
                 }
@@ -954,30 +944,30 @@ bary_pack(int sign, BDIGIT *ds, size_t n https://github.com/ruby/ruby/blob/trunk/bignum.c#L944
         if (nails == 0 && SIZEOF_BDIGITS == sizeof(BDIGIT) &&
             wordsize % SIZEOF_BDIGITS == 0 && (uintptr_t)words % ALIGNOF(BDIGIT) == 0) {
             size_t bdigits_per_word = wordsize / SIZEOF_BDIGITS;
-            size_t buf_num_bdigits = numwords * bdigits_per_word;
+            size_t src_num_bdigits = de - dp;
+            size_t dst_num_bdigits = numwords * bdigits_per_word;
             int overflow = 0;
             int mswordfirst_p = (flags & INTEGER_PACK_MSWORD_FIRST) != 0;
             int msbytefirst_p = (flags & INTEGER_PACK_NATIVE_BYTE_ORDER) ? HOST_BIGENDIAN_P :
                 (flags & INTEGER_PACK_MSBYTE_FIRST) != 0;
-            if (num_bdigits <= buf_num_bdigits) {
-                MEMCPY(words, dp, BDIGIT, num_bdigits);
-                MEMZERO((BDIGIT*)words + num_bdigits, BDIGIT, buf_num_bdigits - num_bdigits);
+            if (src_num_bdigits <= dst_num_bdigits) {
+                MEMCPY(words, dp, BDIGIT, src_num_bdigits);
+                MEMZERO((BDIGIT*)words + src_num_bdigits, BDIGIT, dst_num_bdigits - src_num_bdigits);
             }
             else {
-                MEMCPY(words, dp, BDIGIT, buf_num_bdigits);
+                MEMCPY(words, dp, BDIGIT, dst_num_bdigits);
                 overflow = 1;
             }
             if (sign < 0 && (flags & INTEGER_PACK_2COMP)) {
-                int zero_p = bary_2comp(words, buf_num_bdigits);
-                if (overflow &&
-                    buf_num_bdigits == num_bdigits-1 &&
-                    dp[buf_num_bdigits] == 1 &&
-                    zero_p)
+                int zero_p = bary_2comp(words, dst_num_bdigits);
+                if (zero_p && overflow &&
+                    dst_num_bdigits == src_num_bdigits-1 &&
+                    dp[dst_num_bdigits] == 1)
                     overflow = 0;
             }
             if (msbytefirst_p != HOST_BIGENDIAN_P) {
                 size_t i;
-                for (i = 0; i < buf_num_bdigits; i++) {
+                for (i = 0; i < dst_num_bdigits; i++) {
                     BDIGIT d = ((BDIGIT*)words)[i];
                     ((BDIGIT*)words)[i] = swap_bdigit(d);
                 }
@@ -991,7 +981,7 @@ bary_pack(int sign, BDIGIT *ds, size_t n https://github.com/ruby/ruby/blob/trunk/bignum.c#L981
                 }
             }
             if (mswordfirst_p) {
-                bary_swap(words, buf_num_bdigits);
+                bary_swap(words, dst_num_bdigits);
             }
             if (overflow)
                 sign *= 2;

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

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