From a4088d38f32f00062675fa37f396a31ef5427910 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Thu, 16 Jun 2022 02:27:46 -0400 Subject: [PATCH] apd: add inline fast-path to BigInt.SetString Not important, but easy enough to do and makes a difference for the performance of `Decimal.setString`, which #116 was interested in. --- bigint.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bigint.go b/bigint.go index c50bb85..6271a40 100644 --- a/bigint.go +++ b/bigint.go @@ -886,6 +886,10 @@ func (z *BigInt) SetInt64(x int64) *BigInt { // SetString calls (big.Int).SetString. func (z *BigInt) SetString(s string, base int) (*BigInt, bool) { + if i, err := strconv.ParseInt(s, base, 64); err == nil { + z.SetInt64(i) + return z, true + } var tmp1 big.Int //gcassert:noescape zi := z.inner(&tmp1) if _, ok := zi.SetString(s, base); !ok {