From 092511bac76a4aca95e15107c67deb16272154c5 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 3 Aug 2013 16:01:14 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ bignum.c | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index aff5a024a2..fc0a391c08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Aug 4 00:57:58 2013 Tanaka Akira + + * bignum.c (big2str_karatsuba): Don't allocate new temporary buffer + if the buffer is enough for current invocation. + Sun Aug 4 00:22:34 2013 Tanaka Akira * bignum.c (bary2bdigitdbl): New function. 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) { - wn = bn * 4 + BIGDIVREM_EXTRA_WORDS; - wds = ALLOCV_N(BDIGIT, tmpw, wn); - } 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); + } rds = wds; qds = wds+rn; bary_divmod(qds, qn, rds, rn, xds, xn, bds, bn);