ruby-changes:68395
From: Nobuyoshi <ko1@a...>
Date: Tue, 12 Oct 2021 00:45:26 +0900 (JST)
Subject: [ruby-changes:68395] 6fa1af7ee5 (master): bary_mul_balance_with_mulfunc: consitify invariant variables
https://git.ruby-lang.org/ruby.git/commit/?id=6fa1af7ee5 From 6fa1af7ee5ab88d0be5ae61f5956f7b51b552ee0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 11 Oct 2021 13:28:17 +0900 Subject: bary_mul_balance_with_mulfunc: consitify invariant variables --- bignum.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/bignum.c b/bignum.c index 7adf55d1f0..1f2913da44 100644 --- a/bignum.c +++ b/bignum.c @@ -1641,11 +1641,13 @@ rb_big_sq_fast(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1641 /* balancing multiplication by slicing larger argument */ static void -bary_mul_balance_with_mulfunc(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn, mulfunc_t *mulfunc) +bary_mul_balance_with_mulfunc(BDIGIT *const zds, const size_t zn, + const BDIGIT *const xds, const size_t xn, + const BDIGIT *const yds, const size_t yn, + BDIGIT *wds, size_t wn, mulfunc_t *const mulfunc) { VALUE work = 0; - size_t yn0 = yn; - size_t r, n; + size_t n; assert(xn + yn <= zn); assert(xn <= yn); @@ -1654,13 +1656,11 @@ bary_mul_balance_with_mulfunc(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L1656 BDIGITS_ZERO(zds, xn); n = 0; - while (yn > 0) { - BDIGIT *tds; - size_t tn; - r = xn > yn ? yn : xn; - tn = xn + r; + while (yn > n) { + const size_t r = (xn > (yn - n) ? (yn - n) : xn); + const size_t tn = (xn + r); if (2 * (xn + r) <= zn - n) { - tds = zds + n + xn + r; + BDIGIT *const tds = zds + n + xn + r; mulfunc(tds, tn, xds, xn, yds + n, r, wds, wn); BDIGITS_ZERO(zds + n + xn, r); bary_add(zds + n, tn, @@ -1668,21 +1668,20 @@ bary_mul_balance_with_mulfunc(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L1668 tds, tn); } else { + BDIGIT *const tds = zds + n; if (wn < xn) { wn = xn; wds = ALLOCV_N(BDIGIT, work, wn); } - tds = zds + n; MEMCPY(wds, zds + n, BDIGIT, xn); mulfunc(tds, tn, xds, xn, yds + n, r, wds+xn, wn-xn); bary_add(zds + n, tn, zds + n, tn, wds, xn); } - yn -= r; n += r; } - BDIGITS_ZERO(zds+xn+yn0, zn - (xn+yn0)); + BDIGITS_ZERO(zds+xn+yn, zn - (xn+yn)); if (work) ALLOCV_END(work); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/