Skip to content

Commit

Permalink
- initialize fetchers map with size of length pp.fetchers
Browse files Browse the repository at this point in the history
- use ListPeers in test case.
  • Loading branch information
manu844 committed Dec 17, 2022
1 parent 1fdd87e commit 39d4a10
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ func (pp *PeerPicker) listPeers() map[string]RemoteFetcher {
pp.mu.RLock()
defer pp.mu.RUnlock()

// deep copy of pp.fetchers map.
fetchers := make(map[string]RemoteFetcher)
// deep copy of fetchers map with size equal to length of pp.fetchers.
fetchers := make(map[string]RemoteFetcher, len(pp.fetchers))
for p, f := range pp.fetchers {
fetchers[p] = f
}
Expand Down
2 changes: 1 addition & 1 deletion peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestPeersIncremental(t *testing.T) {
fetcherURIs[f.(*TestFetcher).uri] = struct{}{}
}

allFetchers := u.peerPicker.listPeers()
allFetchers := u.ListPeers()
allPeerIDs := make(map[string]struct{}, len(allFetchers))
allFetcherURIs := make(map[string]struct{}, len(allFetchers))
for peerID, fetcher := range allFetchers {
Expand Down

0 comments on commit 39d4a10

Please sign in to comment.