Skip to content

Commit e9fc080

Browse files
committed
Remove jsonwire.ParseFloat fast path
Calling strconv.ParseFloat() does not allocate now, so the necessity of fast path is reduced. This fast path actually slows down the process when it fails.
1 parent 0640c11 commit e9fc080

File tree

1 file changed

+0
-13
lines changed

1 file changed

+0
-13
lines changed

internal/jsonwire/decode.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,6 @@ func ParseUint(b []byte) (v uint64, ok bool) {
610610
// then we return MaxFloat since any finite value will always be infinitely
611611
// more accurate at representing another finite value than an infinite value.
612612
func ParseFloat(b []byte, bits int) (v float64, ok bool) {
613-
// Fast path for exact integer numbers which fit in the
614-
// 24-bit or 53-bit significand of a float32 or float64.
615-
var negLen int // either 0 or 1
616-
if len(b) > 0 && b[0] == '-' {
617-
negLen = 1
618-
}
619-
u, ok := ParseUint(b[negLen:])
620-
if ok && ((bits == 32 && u <= 1<<24) || (bits == 64 && u <= 1<<53)) {
621-
return math.Copysign(float64(u), float64(-1*negLen)), true
622-
}
623-
624-
// Note that the []byte->string conversion unfortunately allocates.
625-
// See https://go.dev/issue/42429 for more information.
626613
fv, err := strconv.ParseFloat(string(b), bits)
627614
if math.IsInf(fv, 0) {
628615
switch {

0 commit comments

Comments
 (0)