From cc8d40c65ffc3336a4c20d041b2c26142dafd315 Mon Sep 17 00:00:00 2001 From: ucwong Date: Mon, 8 May 2023 00:59:14 -0600 Subject: [PATCH] core/state: initialize maps with known size (#27222) * core/state : fix map size avoid resizing * core/state : fixed size --- core/state/statedb.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index b89f4bfd8c..a4e22baafc 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -783,13 +783,13 @@ func (s *StateDB) Copy() *StateDB { state.snap = s.snap // deep copy needed - state.snapAccounts = make(map[common.Hash][]byte) + state.snapAccounts = make(map[common.Hash][]byte, len(s.snapAccounts)) for k, v := range s.snapAccounts { state.snapAccounts[k] = v } - state.snapStorage = make(map[common.Hash]map[common.Hash][]byte) + state.snapStorage = make(map[common.Hash]map[common.Hash][]byte, len(s.snapStorage)) for k, v := range s.snapStorage { - temp := make(map[common.Hash][]byte) + temp := make(map[common.Hash][]byte, len(v)) for kk, vv := range v { temp[kk] = vv } @@ -1160,7 +1160,7 @@ func (s *StateDB) SlotInAccessList(addr common.Address, slot common.Hash) (addre // convertAccountSet converts a provided account set from address keyed to hash keyed. func (s *StateDB) convertAccountSet(set map[common.Address]struct{}) map[common.Hash]struct{} { - ret := make(map[common.Hash]struct{}) + ret := make(map[common.Hash]struct{}, len(set)) for addr := range set { obj, exist := s.stateObjects[addr] if !exist {