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:
0xFloki 2026-02-02 08:27:37 +01:00 committed by GitHub
parent a5e6a157e5
commit a951aacb70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)