Skip to content

Commit

Permalink
apd: add inline fast-path to BigInt.SetString
Browse files Browse the repository at this point in the history
Not important, but easy enough to do and makes a difference for the
performance of `Decimal.setString`, which cockroachdb#116 was interested in.
  • Loading branch information
nvanbenschoten committed Jun 16, 2022
1 parent 9f9f7a5 commit a4088d3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a4088d3

Please sign in to comment.