Skip to content

Commit

Permalink
refactor(tree): avoid allocation of empty slice of IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
meling committed Dec 24, 2024
1 parent 5f92d28 commit ad4f140
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions internal/tree/treeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,16 @@ func (t *Tree) NodeHeight() int {
return t.heightOf(t.id)
}

// PeersOf returns the peers of given ID, if any.
// PeersOf returns the sibling peers of given ID, if any.
func (t *Tree) PeersOf(nodeID hotstuff.ID) []hotstuff.ID {
peers := make([]hotstuff.ID, 0)
if t.IsRoot(nodeID) {
return peers
return nil
}
parent, ok := t.Parent()
if !ok {
return peers
return nil
}
return t.ChildrenOfNode(parent)
return t.ChildrenOf(parent)
}

// SubTree returns all the nodes of its subtree.
Expand Down

0 comments on commit ad4f140

Please sign in to comment.