diff --git a/core/bootstrap/bootstrap.go b/core/bootstrap/bootstrap.go index e6b4f826d..d7c107690 100644 --- a/core/bootstrap/bootstrap.go +++ b/core/bootstrap/bootstrap.go @@ -20,8 +20,6 @@ import ( "github.com/libp2p/go-libp2p-peer" "github.com/libp2p/go-libp2p-peerstore" "github.com/libp2p/go-libp2p-routing" - - "github.com/ipfs/go-ipfs/thirdparty/math2" ) var log = logging.Logger("bootstrap") @@ -208,13 +206,13 @@ func bootstrapConnect(ctx context.Context, ph host.Host, peers []peerstore.PeerI } func randomSubsetOfPeers(in []peerstore.PeerInfo, max int) []peerstore.PeerInfo { - n := math2.IntMin(max, len(in)) - var out []peerstore.PeerInfo - for _, val := range rand.Perm(len(in)) { - out = append(out, in[val]) - if len(out) >= n { - break - } + if max > len(in) { + max = len(in) + } + + out := make([]peerstore.PeerInfo, max) + for i, val := range rand.Perm(len(in))[:max] { + out[i] = in[val] } return out } diff --git a/thirdparty/math2/math2.go b/thirdparty/math2/math2.go deleted file mode 100644 index e8a75b5f7..000000000 --- a/thirdparty/math2/math2.go +++ /dev/null @@ -1,9 +0,0 @@ -package math2 - -// IntMin returns the smaller of x or y. -func IntMin(x, y int) int { - if x < y { - return x - } - return y -}