Skip to content

Commit 6792670

Browse files
optimize FilterAddrs implementation
1 parent 334b79e commit 6792670

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

multiaddr.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ func (m *multiaddr) ValueForProtocol(code int) (value string, err error) {
189189
// If all filters return true, the address is kept.
190190
func FilterAddrs(a []Multiaddr, filters ...func(Multiaddr) bool) []Multiaddr {
191191
b := make([]Multiaddr, 0, len(a))
192+
addrloop:
192193
for _, addr := range a {
193-
good := true
194194
for _, filter := range filters {
195-
good = good && filter(addr)
196-
}
197-
if good {
198-
b = append(b, addr)
195+
if !filter(addr) {
196+
continue addrloop
197+
}
199198
}
199+
b = append(b, addr)
200200
}
201201
return b
202202
}

0 commit comments

Comments
 (0)