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

ruby-changes:29526

From: akr <ko1@a...>
Date: Sun, 23 Jun 2013 00:52:47 +0900 (JST)
Subject: [ruby-changes:29526] akr:r41578 (trunk): * bignum.c (bytes_zero_p): Extracted from bary_pack.

akr	2013-06-23 00:52:36 +0900 (Sun, 23 Jun 2013)

  New Revision: 41578

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

  Log:
    * bignum.c (bytes_zero_p): Extracted from bary_pack.
      (bary_pack): Use bytes_zero_p.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41577)
+++ ChangeLog	(revision 41578)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun 23 00:51:29 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (bytes_zero_p): Extracted from bary_pack.
+	  (bary_pack): Use bytes_zero_p.
+
 Sun Jun 23 00:16:57 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (MSB): New macro.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41577)
+++ bignum.c	(revision 41578)
@@ -124,6 +124,15 @@ 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)
@@ -929,13 +938,11 @@ bary_pack(int sign, BDIGIT *ds, size_t n https://github.com/ruby/ruby/blob/trunk/bignum.c#L938
             if (sign < 0 && (flags & INTEGER_PACK_2COMP)) {
                 int zero_p = bytes_2comp(words, dst_size);
                 if (zero_p && overflow) {
-                    unsigned char *p = (unsigned char *)dp + dst_size;
-                    unsigned char *e = (unsigned char *)dp + src_size;
-                    if (p < e && *p++ == 1) {
-                        while (p < e && *p == 0)
-                            p++;
-                        if (p == e)
-                            overflow = 0;
+                    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)) {
+                        overflow = 0;
                     }
                 }
             }

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

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