aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-03 16:01:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-03 16:01:14 +0000
commit092511bac76a4aca95e15107c67deb16272154c5 (patch)
tree4a5aa8fcf280a4e8ea6dbbb835ae38205b844444 /bignum.c
parentb3be3c29c47fd9b570e5649bdf46d1a8f08aa3a0 (diff)
downloadruby-092511bac76a4aca95e15107c67deb16272154c5.tar.gz
* bignum.c (big2str_karatsuba): Don't allocate new temporary buffer
if the buffer is enough for current invocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/bignum.c b/bignum.c
index a3e4a0be91..f7599c3449 100644
--- a/bignum.c
+++ b/bignum.c
@@ -4383,12 +4383,13 @@ big2str_karatsuba(struct big2str_struct *b2s, BDIGIT *xds, size_t xn,
memset(b2s->ptr, '0', len);
b2s->ptr += len;
}
- if (wn < bn * 4 + BIGDIVREM_EXTRA_WORDS) {
+ rn = bn;
+ qn = xn+BIGDIVREM_EXTRA_WORDS;
+ if (wn < rn + qn) {
wn = bn * 4 + BIGDIVREM_EXTRA_WORDS;
+ assert(rn + qn <= wn);
wds = ALLOCV_N(BDIGIT, tmpw, wn);
}
- rn = bn;
- qn = xn+BIGDIVREM_EXTRA_WORDS;
rds = wds;
qds = wds+rn;
bary_divmod(qds, qn, rds, rn, xds, xn, bds, bn);