bigint.c (mrb_bint_to_s): shortcut for bigint zero.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-07-20 14:40:45 +09:00
parent a4ce63abc5
commit 450382735b
+3
View File
@@ -1372,6 +1372,9 @@ mrb_value
mrb_bint_to_s(mrb_state *mrb, mrb_value x, mrb_int base)
{
struct RBigint *b = RBIGINT(x);
if (b->mp.sz == 0) return mrb_str_new_lit(mrb, "0");
mrb_int len = mpz_sizeinbase(&b->mp, (int)base);
mrb_value str = mrb_str_new(mrb, NULL, len+2);
mpz_get_str(mrb, RSTRING_PTR(str), len, base, &b->mp);