Merge pull request #2531 from nspcc-dev/perf
Minor performance improvements
This commit is contained in:
commit
edb6ca8926
25 changed files with 198 additions and 99 deletions
13
pkg/util/bench_test.go
Normal file
13
pkg/util/bench_test.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkUint256MarshalJSON(b *testing.B) {
|
||||
v := Uint256{0x01, 0x02, 0x03}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, _ = v.MarshalJSON()
|
||||
}
|
||||
}
|
|
@ -132,7 +132,12 @@ func (u *Uint160) UnmarshalJSON(data []byte) (err error) {
|
|||
|
||||
// MarshalJSON implements the json marshaller interface.
|
||||
func (u Uint160) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"0x` + u.StringLE() + `"`), nil
|
||||
r := make([]byte, 3+Uint160Size*2+1)
|
||||
copy(r, `"0x`)
|
||||
r[len(r)-1] = '"'
|
||||
slice.Reverse(u[:]) // u is a copy, so we can mangle it in any way.
|
||||
hex.Encode(r[3:], u[:])
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the YAML Unmarshaler interface.
|
||||
|
|
|
@ -109,7 +109,12 @@ func (u *Uint256) UnmarshalJSON(data []byte) (err error) {
|
|||
|
||||
// MarshalJSON implements the json marshaller interface.
|
||||
func (u Uint256) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"0x` + u.StringLE() + `"`), nil
|
||||
r := make([]byte, 3+Uint256Size*2+1)
|
||||
copy(r, `"0x`)
|
||||
r[len(r)-1] = '"'
|
||||
slice.Reverse(u[:]) // u is a copy, so we can mangle it in any way.
|
||||
hex.Encode(r[3:], u[:])
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// CompareTo compares two Uint256 with each other. Possible output: 1, -1, 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue