Skip to content

Commit 3169f94

Browse files
qcraojorgemmsilva
authored andcommitted
trie: preallocate capacity for fields slice (ethereum#29614)
trie: Preallocate capacity for fields slice
1 parent 4386abd commit 3169f94

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

trie/trienode/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func NewNodeSet(owner common.Hash) *NodeSet {
7878
// ForEachWithOrder iterates the nodes with the order from bottom to top,
7979
// right to left, nodes with the longest path will be iterated first.
8080
func (set *NodeSet) ForEachWithOrder(callback func(path string, n *Node)) {
81-
var paths []string
81+
paths := make([]string, 0, len(set.Nodes))
8282
for path := range set.Nodes {
8383
paths = append(paths, path)
8484
}
@@ -133,7 +133,7 @@ func (set *NodeSet) Size() (int, int) {
133133
// Hashes returns the hashes of all updated nodes. TODO(rjl493456442) how can
134134
// we get rid of it?
135135
func (set *NodeSet) Hashes() []common.Hash {
136-
var ret []common.Hash
136+
ret := make([]common.Hash, 0, len(set.Nodes))
137137
for _, node := range set.Nodes {
138138
ret = append(ret, node.Hash)
139139
}

0 commit comments

Comments
 (0)