Skip to content

Commit 402e8b6

Browse files
authored
Remove jsonwire.ParseFloat fast path (#139)
Since https://go.dev/cl/345488, converting a []byte to string in order to call strconv.ParseFloat no longer allocates. Remove the fast path as it no longer brings sufficient benefit.
1 parent 4b32ad8 commit 402e8b6

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)