Skip to content

Commit

Permalink
optimizie FilterAddrs implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Dec 14, 2021
1 parent 8e0d03f commit c4491e3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions net/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import ma "github.com/multiformats/go-multiaddr"
// If all filters return true, the address is kept.
func FilterAddrs(a []ma.Multiaddr, filters ...func(ma.Multiaddr) bool) []ma.Multiaddr {
b := make([]ma.Multiaddr, 0, len(a))
addrloop:
for _, addr := range a {
good := true
for _, filter := range filters {
good = good && filter(addr)
}
if good {
b = append(b, addr)
if !filter(addr) {
continue addrloop
}
}
b = append(b, addr)
}
return b
}

0 comments on commit c4491e3

Please sign in to comment.