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 8c18e16 commit db4d4a8
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 db4d4a8

Please sign in to comment.