mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (big2str_orig): Use temporary buffer when trim mode.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
39a00c6710
commit
478bd3128c
2 changed files with 20 additions and 5 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Thu Aug 1 07:36:27 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* bignum.c (big2str_orig): Use temporary buffer when trim mode.
|
||||||
|
|
||||||
Thu Aug 1 06:28:48 2013 Tanaka Akira <akr@fsij.org>
|
Thu Aug 1 06:28:48 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now.
|
* bignum.c (big2str_orig): Simplified because RBIGNUM_LEN(x) <= 2 now.
|
||||||
|
|
21
bignum.c
21
bignum.c
|
@ -4224,13 +4224,23 @@ static size_t
|
||||||
big2str_orig(struct big2str_struct *b2s, VALUE x, char* ptr, size_t len, int trim)
|
big2str_orig(struct big2str_struct *b2s, VALUE x, char* ptr, size_t len, int trim)
|
||||||
{
|
{
|
||||||
long i = RBIGNUM_LEN(x);
|
long i = RBIGNUM_LEN(x);
|
||||||
size_t j = len;
|
size_t j;
|
||||||
int k;
|
int k;
|
||||||
BDIGIT* ds = BDIGITS(x);
|
BDIGIT* ds = BDIGITS(x);
|
||||||
BDIGIT_DBL num;
|
BDIGIT_DBL num;
|
||||||
|
char buf[SIZEOF_BDIGIT_DBL*CHAR_BIT], *p;
|
||||||
|
|
||||||
assert(i <= 2);
|
assert(i <= 2);
|
||||||
|
|
||||||
|
if (trim) {
|
||||||
|
p = buf;
|
||||||
|
j = sizeof(buf);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p = ptr;
|
||||||
|
j = len;
|
||||||
|
}
|
||||||
|
|
||||||
num = 0;
|
num = 0;
|
||||||
if (0 < i)
|
if (0 < i)
|
||||||
num = ds[0];
|
num = ds[0];
|
||||||
|
@ -4239,15 +4249,16 @@ big2str_orig(struct big2str_struct *b2s, VALUE x, char* ptr, size_t len, int tri
|
||||||
|
|
||||||
k = b2s->hbase2_numdigits;
|
k = b2s->hbase2_numdigits;
|
||||||
while (k--) {
|
while (k--) {
|
||||||
ptr[--j] = ruby_digitmap[num % b2s->base];
|
p[--j] = ruby_digitmap[num % b2s->base];
|
||||||
num /= b2s->base;
|
num /= b2s->base;
|
||||||
if (j <= 0) break;
|
if (j <= 0) break;
|
||||||
if (trim && num == 0) break;
|
if (trim && num == 0) break;
|
||||||
}
|
}
|
||||||
if (trim) {
|
if (trim) {
|
||||||
while (j < len && ptr[j] == '0') j++;
|
while (j < sizeof(buf) && p[j] == '0') j++;
|
||||||
MEMMOVE(ptr, ptr + j, char, len - j);
|
assert(sizeof(buf)-j <= len);
|
||||||
len -= j;
|
MEMCPY(ptr, p + j, char, sizeof(buf) - j);
|
||||||
|
len = sizeof(buf) - j;
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue