cmd/evm/internal/t8ntool, core: prealloc map sizes where possible (#29620)

set cap for map in a certain scenario
This commit is contained in:
maskpp 2024-04-30 17:19:59 +08:00 committed by GitHub
parent 8c3fc56d7f
commit fecc8a0f4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

@ -296,7 +296,7 @@ func (g Alloc) OnAccount(addr *common.Address, dumpAccount state.DumpAccount) {
balance, _ := new(big.Int).SetString(dumpAccount.Balance, 0) balance, _ := new(big.Int).SetString(dumpAccount.Balance, 0)
var storage map[common.Hash]common.Hash var storage map[common.Hash]common.Hash
if dumpAccount.Storage != nil { if dumpAccount.Storage != nil {
storage = make(map[common.Hash]common.Hash) storage = make(map[common.Hash]common.Hash, len(dumpAccount.Storage))
for k, v := range dumpAccount.Storage { for k, v := range dumpAccount.Storage {
storage[k] = common.HexToHash(v) storage[k] = common.HexToHash(v)
} }

@ -1309,7 +1309,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
// Delete block data from the main database. // Delete block data from the main database.
var ( var (
batch = bc.db.NewBatch() batch = bc.db.NewBatch()
canonHashes = make(map[common.Hash]struct{}) canonHashes = make(map[common.Hash]struct{}, len(blockChain))
) )
for _, block := range blockChain { for _, block := range blockChain {
canonHashes[block.Hash()] = struct{}{} canonHashes[block.Hash()] = struct{}{}