Skip to content

Commit 7ec72cb

Browse files
committed
pre alloc capacity for nodes and subset
1 parent 18a9027 commit 7ec72cb

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

triedb/pathdb/nodes.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
259259
}
260260
} else {
261261
// Storage nodes
262-
subset := make(map[string]*trienode.Node)
262+
subset := make(map[string]*trienode.Node, len(entry.Nodes))
263263
for _, n := range entry.Nodes {
264264
if len(n.Blob) > 0 {
265265
subset[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob)
@@ -276,13 +276,11 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
276276

277277
// write flushes nodes into the provided database batch as a whole.
278278
func (s *nodeSet) write(batch ethdb.Batch, clean *fastcache.Cache) int {
279-
nodes := make(map[common.Hash]map[string]*trienode.Node)
279+
nodes := make(map[common.Hash]map[string]*trienode.Node, len(s.storageNodes)+1)
280280
if len(s.accountNodes) > 0 {
281281
nodes[common.Hash{}] = s.accountNodes
282282
}
283-
for owner, subset := range s.storageNodes {
284-
nodes[owner] = subset
285-
}
283+
maps.Copy(nodes, s.storageNodes)
286284
return writeNodes(batch, nodes, clean)
287285
}
288286

0 commit comments

Comments
 (0)