From 0887d82406c9a9701acd235e8f510480cea9f218 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 10 Sep 2025 00:23:56 +0900 Subject: [PATCH] dtoa.c: Add shortcut if arguments are zero --- missing/dtoa.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/missing/dtoa.c b/missing/dtoa.c index 8859fcfa44..4d266ecf12 100644 --- a/missing/dtoa.c +++ b/missing/dtoa.c @@ -699,6 +699,8 @@ i2b(int i) return b; } +#define Bzero_p(b) (!(b)->x[0] && (b)->wds <= 1) + static Bigint * mult(Bigint *a, Bigint *b) { @@ -715,6 +717,13 @@ mult(Bigint *a, Bigint *b) #endif #endif + if (Bzero_p(a) || Bzero_p(b)) { + c = Balloc(0); + c->wds = 1; + c->x[0] = 0; + return c; + } + if (a->wds < b->wds) { c = a; a = b; @@ -862,6 +871,8 @@ lshift(Bigint *b, int k) Bigint *b1; ULong *x, *x1, *xe, z; + if (!k || Bzero_p(b)) return b; + #ifdef Pack_32 n = k >> 5; #else