mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2026-08-18 14:53:28 +08:00
remove unnecessary map allocation when adding addresses
This commit is contained in:
@@ -216,15 +216,13 @@ func (mab *memoryAddrBook) addAddrsUnlocked(s *addrSegment, p peer.ID, addrs []m
|
||||
}
|
||||
|
||||
exp := time.Now().Add(ttl)
|
||||
addrSet := make(map[string]struct{}, len(addrs))
|
||||
for _, addr := range addrs {
|
||||
if addr == nil {
|
||||
log.Warnw("was passed nil multiaddr", "peer", p)
|
||||
continue
|
||||
}
|
||||
k := string(addr.Bytes())
|
||||
addrSet[k] = struct{}{}
|
||||
|
||||
k := string(addr.Bytes())
|
||||
// find the highest TTL and Expiry time between
|
||||
// existing records and function args
|
||||
a, found := amap[k] // won't allocate.
|
||||
|
||||
Reference in New Issue
Block a user