mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 15:47:21 +00:00
rlp: optimize intsize (#32421)
goos: darwin
goarch: arm64
pkg: github.com/ethereum/go-ethereum/rlp
cpu: Apple M4
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
Intsize 2.175n ± 5% 1.050n ± 4% -51.76% (p=0.000 n=10)
This commit is contained in:
parent
a4d3fb9805
commit
f054befc55
1 changed files with 4 additions and 4 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"math/big"
|
||||
"math/bits"
|
||||
"reflect"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rlp/internal/rlpstruct"
|
||||
|
|
@ -487,9 +488,8 @@ func putint(b []byte, i uint64) (size int) {
|
|||
|
||||
// intsize computes the minimum number of bytes required to store i.
|
||||
func intsize(i uint64) (size int) {
|
||||
for size = 1; ; size++ {
|
||||
if i >>= 8; i == 0 {
|
||||
return size
|
||||
}
|
||||
if i == 0 {
|
||||
return 1
|
||||
}
|
||||
return (bits.Len64(i) + 7) / 8
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue