common/hexutil: refactor to using bit.UintSize/4 cal the bigWordNibbles

This commit is contained in:
cuiweixie 2025-08-14 20:27:53 +08:00
parent 25cce4dfe4
commit 102e0b2a0d

View file

@ -117,21 +117,7 @@ func EncodeUint64(i uint64) string {
return string(strconv.AppendUint(enc, i, 16)) return string(strconv.AppendUint(enc, i, 16))
} }
var bigWordNibbles int const bigWordNibbles int = bits.UintSize / 4
func init() {
// This is a weird way to compute the number of nibbles required for big.Word.
// The usual way would be to use constant arithmetic but go vet can't handle that.
b, _ := new(big.Int).SetString("FFFFFFFFFF", 16)
switch len(b.Bits()) {
case 1:
bigWordNibbles = 16
case 2:
bigWordNibbles = 8
default:
panic("weird big.Word size")
}
}
// DecodeBig decodes a hex string with 0x prefix as a quantity. // DecodeBig decodes a hex string with 0x prefix as a quantity.
// Numbers larger than 256 bits are not accepted. // Numbers larger than 256 bits are not accepted.