mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
pre alloc capacity for nodes and subset
This commit is contained in:
parent
18a902799e
commit
7ec72cb807
1 changed files with 3 additions and 5 deletions
|
|
@ -259,7 +259,7 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Storage nodes
|
// Storage nodes
|
||||||
subset := make(map[string]*trienode.Node)
|
subset := make(map[string]*trienode.Node, len(entry.Nodes))
|
||||||
for _, n := range entry.Nodes {
|
for _, n := range entry.Nodes {
|
||||||
if len(n.Blob) > 0 {
|
if len(n.Blob) > 0 {
|
||||||
subset[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob)
|
subset[string(n.Path)] = trienode.New(crypto.Keccak256Hash(n.Blob), n.Blob)
|
||||||
|
|
@ -276,13 +276,11 @@ func (s *nodeSet) decode(r *rlp.Stream) error {
|
||||||
|
|
||||||
// write flushes nodes into the provided database batch as a whole.
|
// write flushes nodes into the provided database batch as a whole.
|
||||||
func (s *nodeSet) write(batch ethdb.Batch, clean *fastcache.Cache) int {
|
func (s *nodeSet) write(batch ethdb.Batch, clean *fastcache.Cache) int {
|
||||||
nodes := make(map[common.Hash]map[string]*trienode.Node)
|
nodes := make(map[common.Hash]map[string]*trienode.Node, len(s.storageNodes)+1)
|
||||||
if len(s.accountNodes) > 0 {
|
if len(s.accountNodes) > 0 {
|
||||||
nodes[common.Hash{}] = s.accountNodes
|
nodes[common.Hash{}] = s.accountNodes
|
||||||
}
|
}
|
||||||
for owner, subset := range s.storageNodes {
|
maps.Copy(nodes, s.storageNodes)
|
||||||
nodes[owner] = subset
|
|
||||||
}
|
|
||||||
return writeNodes(batch, nodes, clean)
|
return writeNodes(batch, nodes, clean)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue