Merge pull request #2133 from nspcc-dev/optimize-util
util: reduce allocations in `util.Uint256DecodeStringLE`
This commit is contained in:
commit
483934d3a6
2 changed files with 15 additions and 1 deletions
|
@ -26,7 +26,8 @@ func Uint256DecodeStringLE(s string) (u Uint256, err error) {
|
|||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
return Uint256DecodeBytesLE(b)
|
||||
slice.Reverse(b)
|
||||
return Uint256DecodeBytesBE(b)
|
||||
}
|
||||
|
||||
// Uint256DecodeStringBE attempts to decode the given string (in BE representation)
|
||||
|
|
|
@ -95,3 +95,16 @@ func TestUint256_Serializable(t *testing.T) {
|
|||
var b util.Uint256
|
||||
testserdes.EncodeDecodeBinary(t, &a, &b)
|
||||
}
|
||||
|
||||
func BenchmarkUint256DecodeStringLE(b *testing.B) {
|
||||
a := "f037308fa0ab18155bccfc08485468c112409ea5064595699e98c545f245f32d"
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := util.Uint256DecodeStringLE(a)
|
||||
if err != nil {
|
||||
b.FailNow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue