Skip to content

Commit

Permalink
tree: avoid memory allocs while collecting paths (#371)
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
  • Loading branch information
jsign committed Jul 10, 2023
1 parent 05ed019 commit 43e78a2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,14 @@ func (n *InternalNode) collectNonHashedNodes(list []VerkleNode, paths [][]byte,
list = append(list, n)
paths = append(paths, path)
for i, child := range n.children {
childpath := make([]byte, len(path)+1)
copy(childpath, path)
childpath[len(path)] = byte(i)
switch childNode := child.(type) {
case *LeafNode:
list = append(list, childNode)
paths = append(paths, childpath)
paths = append(paths, childNode.stem[:len(path)+1])
case *InternalNode:
childpath := make([]byte, len(path)+1)
copy(childpath, path)
childpath[len(path)] = byte(i)
list, paths = childNode.collectNonHashedNodes(list, paths, childpath)
}
}
Expand Down

0 comments on commit 43e78a2

Please sign in to comment.