Skip to content

Commit

Permalink
refactor(tree): allocate less in SubTree() method
Browse files Browse the repository at this point in the history
  • Loading branch information
meling committed Dec 24, 2024
1 parent 8945718 commit e470824
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/tree/treeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ func (t *Tree) SubTree() []hotstuff.ID {
if len(children) == 0 {
return nil
}
subTreeReplicas := slices.Clone(children)
queue := slices.Clone(children)
for len(queue) > 0 {
child := queue[0]
queue = queue[1:]
children := t.ChildrenOf(child)
subTreeReplicas = append(subTreeReplicas, children...)
queue = append(queue, children...)
subTreeReplicas := make([]hotstuff.ID, len(children))
copy(subTreeReplicas, children)
for i := 0; i < len(subTreeReplicas); i++ {
node := subTreeReplicas[i]
newChildren := t.ChildrenOf(node)
subTreeReplicas = append(subTreeReplicas, newChildren...)
}
return subTreeReplicas
}
Expand Down

0 comments on commit e470824

Please sign in to comment.