From 6ca4389e18f168175555d51e62ffba42107f6aef Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 14 Dec 2021 18:58:51 +0400 Subject: [PATCH] optimize map lookup when adding addresses --- pstoremem/addr_book.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pstoremem/addr_book.go b/pstoremem/addr_book.go index 1c823d0..f241913 100644 --- a/pstoremem/addr_book.go +++ b/pstoremem/addr_book.go @@ -222,15 +222,13 @@ func (mab *memoryAddrBook) addAddrsUnlocked(s *addrSegment, p peer.ID, addrs []m continue } - k := string(addr.Bytes()) // find the highest TTL and Expiry time between // existing records and function args - a, found := amap[k] // won't allocate. - + a, found := amap[string(addr.Bytes())] // won't allocate. if !found { // not found, announce it. entry := &expiringAddr{Addr: addr, Expires: exp, TTL: ttl} - amap[k] = entry + amap[string(addr.Bytes())] = entry mab.subManager.BroadcastAddr(p, addr) } else { // update ttl & exp to whichever is greater between new and existing entry