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 Jul 14, 2024
1 parent 4937e59 commit f025292
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 @@ -92,13 +92,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 f025292

Please sign in to comment.