remove unnecessary map allocation when adding addresses

This commit is contained in:
Marten Seemann 2021-12-14 18:56:28 +04:00
parent 4ff41e6ed1
commit 8354ce4655

View File

@ -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.