diff --git a/core/genesis.go b/core/genesis.go index 42836e0269..738e68cb45 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -624,7 +624,7 @@ func decodePrealloc(data string) types.GenesisAlloc { acc.Nonce = account.Misc.Nonce acc.Code = account.Misc.Code - acc.Storage = make(map[common.Hash]common.Hash) + acc.Storage = make(map[common.Hash]common.Hash, len(account.Misc.Slots)) for _, slot := range account.Misc.Slots { acc.Storage[slot.Key] = slot.Val } diff --git a/node/rpcstack.go b/node/rpcstack.go index 6d3828ec2b..4e85c5bb3b 100644 --- a/node/rpcstack.go +++ b/node/rpcstack.go @@ -436,7 +436,7 @@ type virtualHostHandler struct { } func newVHostHandler(vhosts []string, next http.Handler) http.Handler { - vhostMap := make(map[string]struct{}) + vhostMap := make(map[string]struct{}, len(vhosts)) for _, allowedHost := range vhosts { vhostMap[strings.ToLower(allowedHost)] = struct{}{} } @@ -636,7 +636,7 @@ func RegisterApis(apis []rpc.API, modules []string, srv *rpc.Server) error { log.Error("Unavailable modules in HTTP API list", "unavailable", bad, "available", available) } // Generate the allow list based on the allowed modules - allowList := make(map[string]bool) + allowList := make(map[string]bool, len(modules)) for _, module := range modules { allowList[module] = true } diff --git a/rpc/server.go b/rpc/server.go index 52866004f8..47f15b1dd2 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -190,7 +190,7 @@ func (s *RPCService) Modules() map[string]string { s.server.services.mu.Lock() defer s.server.services.mu.Unlock() - modules := make(map[string]string) + modules := make(map[string]string, len(s.server.services.services)) for name := range s.server.services.services { modules[name] = "1.0" } diff --git a/triedb/pathdb/nodebuffer.go b/triedb/pathdb/nodebuffer.go index 5675f14123..ff09484100 100644 --- a/triedb/pathdb/nodebuffer.go +++ b/triedb/pathdb/nodebuffer.go @@ -90,7 +90,7 @@ func (b *nodebuffer) commit(nodes map[common.Hash]map[string]*trienode.Node) *no // The nodes belong to original diff layer are still accessible even // after merging, thus the ownership of nodes map should still belong // to original layer and any mutation on it should be prevented. - current = make(map[string]*trienode.Node) + current = make(map[string]*trienode.Node, len(subset)) for path, n := range subset { current[path] = n delta += int64(len(n.Blob) + len(path))