mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-03-22 12:50:07 +08:00
remove unnecessary map allocation when adding addresses
This commit is contained in:
parent
4ff41e6ed1
commit
8354ce4655
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user