* bignum.c (bytes_zero_p): Extracted from bary_pack.
(bary_pack): Use bytes_zero_p. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
31415e5809
commit
f175d5259c
@ -1,3 +1,8 @@
|
|||||||
|
Sun Jun 23 00:51:29 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* 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@fsij.org>
|
Sun Jun 23 00:16:57 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (MSB): New macro.
|
* bignum.c (MSB): New macro.
|
||||||
|
21
bignum.c
21
bignum.c
@ -123,6 +123,15 @@ rb_big_dump(VALUE x)
|
|||||||
#define ON_DEBUG(x)
|
#define ON_DEBUG(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int
|
||||||
|
bytes_zero_p(unsigned char *p, size_t n)
|
||||||
|
{
|
||||||
|
while (n--)
|
||||||
|
if (*p++)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bary_zero_p(BDIGIT *xds, size_t nx)
|
bary_zero_p(BDIGIT *xds, size_t nx)
|
||||||
{
|
{
|
||||||
@ -929,13 +938,11 @@ bary_pack(int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords
|
|||||||
if (sign < 0 && (flags & INTEGER_PACK_2COMP)) {
|
if (sign < 0 && (flags & INTEGER_PACK_2COMP)) {
|
||||||
int zero_p = bytes_2comp(words, dst_size);
|
int zero_p = bytes_2comp(words, dst_size);
|
||||||
if (zero_p && overflow) {
|
if (zero_p && overflow) {
|
||||||
unsigned char *p = (unsigned char *)dp + dst_size;
|
unsigned char *p = (unsigned char *)dp;
|
||||||
unsigned char *e = (unsigned char *)dp + src_size;
|
if (dst_size < src_size &&
|
||||||
if (p < e && *p++ == 1) {
|
p[dst_size] == 1 &&
|
||||||
while (p < e && *p == 0)
|
bytes_zero_p(p+dst_size+1, src_size-dst_size-1)) {
|
||||||
p++;
|
overflow = 0;
|
||||||
if (p == e)
|
|
||||||
overflow = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user