Skip to content

Commit

Permalink
Avoid extra pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Sep 14, 2024
1 parent d517ab9 commit c7626c0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions p2p/host/peerstore/pstoremem/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type peerAddrs struct {
expiringHeap []*expiringAddr
}

func newPeerAddrs() *peerAddrs {
return &peerAddrs{
func newPeerAddrs() peerAddrs {
return peerAddrs{
addrs: make(map[peer.ID]map[string]*expiringAddr),
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (rc realclock) Now() time.Time {
type memoryAddrBook struct {
mu sync.RWMutex
// TODO bound the number of not connected addresses we store.
addrs *peerAddrs
addrs peerAddrs
signedPeerRecords map[peer.ID]*peerRecordState

refCount sync.WaitGroup
Expand Down Expand Up @@ -299,7 +299,7 @@ func (mab *memoryAddrBook) addAddrsUnlocked(p peer.ID, addrs []ma.Multiaddr, ttl
if !found {
// not found, announce it.
entry := &expiringAddr{Addr: addr, Expires: exp, TTL: ttl, Peer: p}
heap.Push(mab.addrs, entry)
heap.Push(&mab.addrs, entry)
mab.subManager.BroadcastAddr(p, addr)
} else {
// update ttl & exp to whichever is greater between new and existing entry
Expand Down Expand Up @@ -355,7 +355,7 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du
}
} else {
if ttl > 0 {
heap.Push(mab.addrs, &expiringAddr{Addr: addr, Expires: exp, TTL: ttl, Peer: p})
heap.Push(&mab.addrs, &expiringAddr{Addr: addr, Expires: exp, TTL: ttl, Peer: p})
mab.subManager.BroadcastAddr(p, addr)
}
}
Expand Down

0 comments on commit c7626c0

Please sign in to comment.