From 6274f8de4316d9dea051e84b3d07061e94cdfeb2 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 1 Oct 2024 15:48:21 +0900 Subject: [PATCH] mruby-bigint (mpz_sub): avoid data copy Since mpz_sub() calls mpz_add() with opposite sign, refer same data from the original, instead of copying whole data. --- mrbgems/mruby-bigint/core/bigint.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index e3d5406f7..b67111443 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -329,10 +329,10 @@ mpz_sub(mrb_state *mrb, mpz_t *z, mpz_t *x, mpz_t *y) mpz_t u; mpz_init(mrb, &u); - mpz_set(mrb, &u, y); - u.sn = -(u.sn); + u.p = y->p; + u.sz = y->sz; + u.sn = -(y->sn); mpz_add(mrb, z, x, &u); - mpz_clear(mrb, &u); } /* x = y - n */