From e9c896408a795c8f2934a2154704e34cbed671e2 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 26 Jul 2025 22:31:16 +0900 Subject: [PATCH] mruby-bigint: convert simple add/sub operations to use simplified api Simplified several Ruby bigint operations by removing redundant mpz_init calls: - mrb_bint_add_n: mpz_add now handles initialization internally - mrb_bint_sub_n: mpz_sub now handles initialization internally - mrb_bint_add_ii: mpz_add now handles initialization internally - mrb_bint_sub_ii: mpz_sub now handles initialization internally These changes demonstrate the benefit of the *_auto API - operations that previously required separate init + operation calls now work with just the operation call, as the simplified functions handle memory allocation automatically. Co-authored-by: Claude --- mrbgems/mruby-bigint/core/bigint.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index 75b8ec1ed..e14933d71 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -3005,7 +3005,6 @@ mrb_bint_add_n(mrb_state *mrb, mrb_value x, mrb_value y) } y = mrb_as_bint(mrb, y); bint_as_mpz(RBIGINT(y), &b); - mpz_init(&ctx, &z); mpz_add(&ctx, &z, &a, &b); struct RBigint *v = bint_new(mrb, &z); return mrb_obj_value(v); @@ -3049,7 +3048,6 @@ mrb_bint_sub_n(mrb_state *mrb, mrb_value x, mrb_value y) } y = mrb_as_bint(mrb, y); bint_as_mpz(RBIGINT(y), &b); - mpz_init(&ctx, &z); mpz_sub(&ctx, &z, &a, &b); struct RBigint *v = bint_new(mrb, &z); return mrb_obj_value(v); @@ -3145,7 +3143,6 @@ mrb_bint_add_ii(mrb_state *mrb, mrb_int x, mrb_int y) mpz_init_set_int(&ctx, &a, x); mpz_init_set_int(&ctx, &b, y); - mpz_init(&ctx, &z); mpz_add(&ctx, &z, &a, &b); mpz_clear(&ctx, &a); mpz_clear(&ctx, &b); @@ -3160,7 +3157,6 @@ mrb_bint_sub_ii(mrb_state *mrb, mrb_int x, mrb_int y) mpz_init_set_int(&ctx, &a, x); mpz_init_set_int(&ctx, &b, y); - mpz_init(&ctx, &z); mpz_sub(&ctx, &z, &a, &b); mpz_clear(&ctx, &a); mpz_clear(&ctx, &b);