Skip to content

Commit

Permalink
Reduce allocations in Networks
Browse files Browse the repository at this point in the history
Slice length of 64 is used as most IPv6 trees will have that as their
maximum depth.
  • Loading branch information
oschwald committed Aug 15, 2024
1 parent c1c6a5e commit a98fe70
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions traverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
})
}

nodes := []netNode{
{
nodes := make([]netNode, 0, 64)
nodes = append(nodes,
netNode{
ip: prefix.Addr(),
bit: uint(bit),
pointer: pointer,
},
}
)

for len(nodes) > 0 {
node := nodes[len(nodes)-1]
Expand Down

0 comments on commit a98fe70

Please sign in to comment.