From 3e695f24d90099e361ae85198753bd7f318d6cf9 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 14 Jan 2026 16:12:23 +0900 Subject: [PATCH] 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 --- mrbgems/mruby-bigint/core/bigint.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index 6653237b8..1db4f0fb0 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -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;