Skip to content

Commit e774f01

Browse files
committed
fix: optimize isRelay
This function is called frequently, let's avoid allocating as much as possible.
1 parent 6b94711 commit e774f01

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

dht_filters.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ func sameV6Net(a, b net.IP) bool {
166166
}
167167

168168
func isRelayAddr(a ma.Multiaddr) bool {
169-
for _, p := range a.Protocols() {
170-
if p.Code == ma.P_CIRCUIT {
171-
return true
172-
}
173-
}
174-
return false
169+
found := false
170+
ma.ForEach(a, func(c ma.Component) bool {
171+
found = c.Protocol().Code == ma.P_CIRCUIT
172+
return !found
173+
})
174+
return found
175175
}

0 commit comments

Comments
 (0)