From fecc8a0f4a5b4f42825ccc1628d069e6eceaba49 Mon Sep 17 00:00:00 2001 From: maskpp Date: Tue, 30 Apr 2024 17:19:59 +0800 Subject: [PATCH] cmd/evm/internal/t8ntool, core: prealloc map sizes where possible (#29620) set cap for map in a certain scenario --- cmd/evm/internal/t8ntool/transition.go | 2 +- core/blockchain.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 2b5eaa65aa..9ea94d195e 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -296,7 +296,7 @@ func (g Alloc) OnAccount(addr *common.Address, dumpAccount state.DumpAccount) { balance, _ := new(big.Int).SetString(dumpAccount.Balance, 0) var storage map[common.Hash]common.Hash 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 { storage[k] = common.HexToHash(v) } diff --git a/core/blockchain.go b/core/blockchain.go index e4c8966824..9de4baccca 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1309,7 +1309,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ // Delete block data from the main database. var ( batch = bc.db.NewBatch() - canonHashes = make(map[common.Hash]struct{}) + canonHashes = make(map[common.Hash]struct{}, len(blockChain)) ) for _, block := range blockChain { canonHashes[block.Hash()] = struct{}{}