Closed rski closed 9 months ago
huh, looking at the code, this shouldn't be happening. I'm confused
ah, ok I understand. This is specifically for MaxInt64, Int64 variables do suggest FormatInt correctly
So, should I close this issue ?
For the input
package main
import (
"fmt"
"math"
)
func main() {
foo := int64(math.MaxInt64)
fmt.Sprintf("%d", foo)
}
I get fmt.Sprintf can be replaced with faster strconv.FormatInt
as expected
the problem is this input:
func main() {
foo := math.MaxInt64
fmt.Sprintf("%d", foo)
}
which suggests Itoa. in 64 bit this would work, but in 32 bit no.I think maybe untyped int constants need to be compared against maxint32 and suggest FormatInt or Itoa based on that
Well, golang stdlib defines math.MaxInt64
as an int
It looks like program with math.MaxInt64
cannot compile/run on 32-bit architectures cf https://stackoverflow.com/questions/60392921/why-is-math-maxint64-inferred-as-int32
So perfsprint is working as expected here
e.g. in:
https://pkg.go.dev/strconv#Itoa takes an int, which is as at least as big as an int32, meaning it might not hold an int64. For int64, https://pkg.go.dev/strconv#FormatInt should be suggested instead