[前][次][番号順一覧][スレッド一覧]

ruby-changes:68394

From: Nobuyoshi <ko1@a...>
Date: Tue, 12 Oct 2021 00:45:25 +0900 (JST)
Subject: [ruby-changes:68394] 373b399823 (master): bary_mul_balance_with_mulfunc: move working buffer allocation

https://git.ruby-lang.org/ruby.git/commit/?id=373b399823

From 373b399823e0c5ab315df76f82467fca27ec40d6 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 11 Oct 2021 17:33:59 +0900
Subject: bary_mul_balance_with_mulfunc: move working buffer allocation

Move the allocation of working buffer before the loop.
---
 bignum.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/bignum.c b/bignum.c
index 1f2913da44..c74df3f4da 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1655,6 +1655,14 @@ bary_mul_balance_with_mulfunc(BDIGIT *const zds, const size_t zn, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1655
 
     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, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1678
         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);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]