mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-02-06 06:20:06 +08:00
preallocate AddrStream buffer
This commit is contained in:
parent
b99e11911a
commit
eaa5f7e9e7
@ -267,7 +267,7 @@ func (mgr *AddrManager) AddrStream(ctx context.Context, p peer.ID) <-chan ma.Mul
|
||||
mgr.addrSubs[p] = append(mgr.addrSubs[p], sub)
|
||||
|
||||
baseaddrset := mgr.addrs[p]
|
||||
var initial []ma.Multiaddr
|
||||
initial := make([]ma.Multiaddr, 0, len(baseaddrset))
|
||||
for _, a := range baseaddrset {
|
||||
initial = append(initial, a.Addr)
|
||||
}
|
||||
@ -277,7 +277,7 @@ func (mgr *AddrManager) AddrStream(ctx context.Context, p peer.ID) <-chan ma.Mul
|
||||
go func(buffer []ma.Multiaddr) {
|
||||
defer close(out)
|
||||
|
||||
sent := make(map[string]bool)
|
||||
sent := make(map[string]bool, len(buffer))
|
||||
var outch chan ma.Multiaddr
|
||||
|
||||
for _, a := range buffer {
|
||||
|
Loading…
Reference in New Issue
Block a user