From c4491e359a80d131447a2d4b74b346ebd5773205 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 14 Dec 2021 17:02:31 +0400 Subject: [PATCH] optimizie FilterAddrs implementation --- net/filter.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/filter.go b/net/filter.go index dbfd287..e8caa2e 100644 --- a/net/filter.go +++ b/net/filter.go @@ -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 }