mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
triedb/pathdb: preallocate slices in encode methods (#33736)
Preallocates slices with known capacity in `stateSet.encode()` and `StateSetWithOrigin.encode()` methods to eliminate redundant reallocations during serialization.
This commit is contained in:
parent
a5e6a157e5
commit
a951aacb70
1 changed files with 8 additions and 2 deletions
|
|
@ -342,7 +342,10 @@ func (s *stateSet) encode(w io.Writer) error {
|
|||
AddrHashes []common.Hash
|
||||
Accounts [][]byte
|
||||
}
|
||||
var enc accounts
|
||||
enc := accounts{
|
||||
AddrHashes: make([]common.Hash, 0, len(s.accountData)),
|
||||
Accounts: make([][]byte, 0, len(s.accountData)),
|
||||
}
|
||||
for addrHash, blob := range s.accountData {
|
||||
enc.AddrHashes = append(enc.AddrHashes, addrHash)
|
||||
enc.Accounts = append(enc.Accounts, blob)
|
||||
|
|
@ -505,7 +508,10 @@ func (s *StateSetWithOrigin) encode(w io.Writer) error {
|
|||
Addresses []common.Address
|
||||
Accounts [][]byte
|
||||
}
|
||||
var accounts Accounts
|
||||
accounts := Accounts{
|
||||
Addresses: make([]common.Address, 0, len(s.accountOrigin)),
|
||||
Accounts: make([][]byte, 0, len(s.accountOrigin)),
|
||||
}
|
||||
for address, blob := range s.accountOrigin {
|
||||
accounts.Addresses = append(accounts.Addresses, address)
|
||||
accounts.Accounts = append(accounts.Accounts, blob)
|
||||
|
|
|
|||
Loading…
Reference in a new issue