diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-09-10 00:23:56 +0900 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-09-10 15:34:29 +0900 |
| commit | 0887d82406c9a9701acd235e8f510480cea9f218 (patch) | |
| tree | fa4863a6248e6508f9a2d18fd8c7b992155eefb7 | |
| parent | 6a4222f47519fe79ab940c9f653b0fad0771176f (diff) | |
dtoa.c: Add shortcut if arguments are zero
| -rw-r--r-- | missing/dtoa.c | 11 |
1 files changed, 11 insertions, 0 deletions
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 |
