preallocated capacity for map's certain usege of memory

This commit is contained in:
maskpp 2024-05-01 10:23:53 +08:00
parent 9f96e07c1c
commit 1d06df1c1f
4 changed files with 5 additions and 5 deletions

View file

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

View file

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

View file

@ -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"
}

View file

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