Commit 67926707 authored by Marten Seemann's avatar Marten Seemann

optimize FilterAddrs implementation

parent 334b79e5
......@@ -189,14 +189,14 @@ func (m *multiaddr) ValueForProtocol(code int) (value string, err error) {
// If all filters return true, the address is kept.
func FilterAddrs(a []Multiaddr, filters ...func(Multiaddr) bool) []Multiaddr {
b := make([]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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment