mruby-bigint: use mpz_init_temp in div_limb for pool allocation

convert mpz_init_heap to mpz_init_temp for temporary quotient and
remainder variables in div_limb. these variables are now allocated
from the memory pool when possible, reducing heap allocation overhead.

the div_limb function already uses pool_save/pool_restore, so these
temporary variables are proper candidates for pool allocation.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-01-14 16:12:23 +09:00
parent 907b4b99d1
commit 3e695f24d9
+5 -5
View File
@@ -2165,7 +2165,7 @@ div_limb(mpz_ctx_t *ctx, mpz_t *q, mpz_t *r, mpz_t *x, mp_limb d)
}
else {
size_t new_size = x->sz - limb_shift;
mpz_init_heap(ctx, &temp_q, new_size);
mpz_init_temp(ctx, &temp_q, new_size);
mpz_init(ctx, &temp_r);
if (bit_shift == 0) {
@@ -2203,8 +2203,8 @@ div_limb(mpz_ctx_t *ctx, mpz_t *q, mpz_t *r, mpz_t *x, mp_limb d)
/* General single-limb division */
if (x->sz == 1) {
/* Both dividend and divisor are single limb */
mpz_init_heap(ctx, &temp_q, 1);
mpz_init_heap(ctx, &temp_r, 1);
mpz_init_temp(ctx, &temp_q, 1);
mpz_init_temp(ctx, &temp_r, 1);
temp_q.p[0] = x->p[0] / d;
temp_r.p[0] = x->p[0] % d;
@@ -2221,8 +2221,8 @@ div_limb(mpz_ctx_t *ctx, mpz_t *q, mpz_t *r, mpz_t *x, mp_limb d)
/* Multi-limb dividend, single-limb divisor */
n = x->sz;
mpz_init_heap(ctx, &temp_q, n);
mpz_init_heap(ctx, &temp_r, 1);
mpz_init_temp(ctx, &temp_q, n);
mpz_init_temp(ctx, &temp_r, 1);
remainder = 0;