From e3a459d5b9d0a08d1d41977d567fc410318e5942 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 24 Jul 2024 15:13:47 +0900 Subject: [PATCH] mruby-bigint (mrb_bint_and): optimize bint & fixnum operation; ref #6314 --- mrbgems/mruby-bigint/core/bigint.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index a8121c404..81dffcbc5 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -1507,6 +1507,13 @@ mrb_bint_and(mrb_state *mrb, mrb_value x, mrb_value y) struct RBigint *b1 = RBIGINT(x); struct RBigint *b3 = bint_new(mrb); + if (mrb_integer_p(y)) { + mrb_int z = mrb_integer(y); + if (z < DIG_BASE) { + z &= b1->mp.p[0]; + return mrb_int_value(mrb, z); + } + } y = mrb_as_bint(mrb, y); struct RBigint *b2 = RBIGINT(y); mpz_and(mrb, &b3->mp, &b1->mp, &b2->mp);