1
0
Fork 0
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:
Nobuyoshi Nakada 2021-10-11 17:33:59 +09:00
parent 6fa1af7ee5
commit 373b399823
Notes: git 2021-10-12 00:45:34 +09:00

View file

@ -1655,6 +1655,14 @@ bary_mul_balance_with_mulfunc(BDIGIT *const zds, const size_t zn,
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;
while (yn > n) {
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 {
BDIGIT *const tds = zds + n;
if (wn < xn) {
/* xn is invariant, only once here */
#if 0
wn = xn;
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);
mulfunc(tds, tn, xds, xn, yds + n, r, wds+xn, wn-xn);