all: use fmt.Appendf instead of fmt.Sprintf where possible #31301 (#1432)

This commit is contained in:
Daniel Liu 2025-09-06 17:12:19 +08:00 committed by GitHub
parent a85b4ee518
commit 06b2524fb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -71,7 +71,7 @@ func (i *HexOrDecimal256) MarshalText() ([]byte, error) {
if i == nil {
return []byte("0x0"), nil
}
return []byte(fmt.Sprintf("%#x", (*big.Int)(i))), nil
return fmt.Appendf(nil, "%#x", (*big.Int)(i)), nil
}
// ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax.

View file

@ -48,7 +48,7 @@ func (i *HexOrDecimal64) UnmarshalText(input []byte) error {
// MarshalText implements encoding.TextMarshaler.
func (i HexOrDecimal64) MarshalText() ([]byte, error) {
return []byte(fmt.Sprintf("%#x", uint64(i))), nil
return fmt.Appendf(nil, "%#x", uint64(i)), nil
}
// ParseUint64 parses s as an integer in decimal or hexadecimal syntax.

View file

@ -279,7 +279,7 @@ func BuildValidatorFromM2(listM2 []int64) []byte {
var validatorBytes []byte
for _, numberM2 := range listM2 {
// Convert number to byte.
m2Byte := common.LeftPadBytes([]byte(fmt.Sprintf("%d", numberM2)), utils.M2ByteLength)
m2Byte := common.LeftPadBytes(fmt.Appendf(nil, "%d", numberM2), utils.M2ByteLength)
validatorBytes = append(validatorBytes, m2Byte...)
}