mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
bary_mul_balance_with_mulfunc: move working buffer allocation
Move the allocation of working buffer before the loop.
This commit is contained in:
parent
6fa1af7ee5
commit
373b399823
Notes:
git
2021-10-12 00:45:34 +09:00
1 changed files with 13 additions and 0 deletions
13
bignum.c
13
bignum.c
|
@ -1655,6 +1655,14 @@ bary_mul_balance_with_mulfunc(BDIGIT *const zds, const size_t zn,
|
||||||
|
|
||||||
BDIGITS_ZERO(zds, xn);
|
BDIGITS_ZERO(zds, xn);
|
||||||
|
|
||||||
|
if (wn < xn) {
|
||||||
|
const size_t r = (yn % xn) ? (yn % xn) : xn;
|
||||||
|
if ((2 * xn + yn + r) > zn) {
|
||||||
|
wn = xn;
|
||||||
|
wds = ALLOCV_N(BDIGIT, work, wn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
while (yn > n) {
|
while (yn > n) {
|
||||||
const size_t r = (xn > (yn - n) ? (yn - n) : xn);
|
const size_t r = (xn > (yn - n) ? (yn - n) : xn);
|
||||||
|
@ -1670,8 +1678,13 @@ bary_mul_balance_with_mulfunc(BDIGIT *const zds, const size_t zn,
|
||||||
else {
|
else {
|
||||||
BDIGIT *const tds = zds + n;
|
BDIGIT *const tds = zds + n;
|
||||||
if (wn < xn) {
|
if (wn < xn) {
|
||||||
|
/* xn is invariant, only once here */
|
||||||
|
#if 0
|
||||||
wn = xn;
|
wn = xn;
|
||||||
wds = ALLOCV_N(BDIGIT, work, wn);
|
wds = ALLOCV_N(BDIGIT, work, wn);
|
||||||
|
#else
|
||||||
|
rb_bug("wds is not enough: %" PRIdSIZE " for %" PRIdSIZE, wn, xn);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
MEMCPY(wds, zds + n, BDIGIT, xn);
|
MEMCPY(wds, zds + n, BDIGIT, xn);
|
||||||
mulfunc(tds, tn, xds, xn, yds + n, r, wds+xn, wn-xn);
|
mulfunc(tds, tn, xds, xn, yds + n, r, wds+xn, wn-xn);
|
||||||
|
|
Loading…
Reference in a new issue