client.go | 3 ++- connection.go | 3 ++- metainfo/metainfo.go | 5 ++--- torrent.go | 7 ++++--- diff --git a/client.go b/client.go index e5cdf0c2ae367eeb7aee0d401b16aa22708f0da8..1491b25d547841e9075d062c921678467f283711 100644 --- a/client.go +++ b/client.go @@ -21,6 +21,7 @@ "github.com/anacrolix/missinggo" "github.com/anacrolix/missinggo/pproffd" "github.com/anacrolix/missinggo/pubsub" + "github.com/anacrolix/missinggo/slices" "github.com/anacrolix/sync" "github.com/anacrolix/utp" "github.com/dustin/go-humanize" @@ -1779,7 +1780,7 @@ func (cl *Client) AddTorrent(mi *metainfo.MetaInfo) (T *Torrent, err error) { T, _, err = cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi)) var ss []string - missinggo.CastSlice(&ss, mi.Nodes) + slices.MakeInto(&ss, mi.Nodes) cl.AddDHTNodes(ss) return } diff --git a/connection.go b/connection.go index a58647ad628b4589620dedebf8c19c0de5fede93..80ef299997e396decbfbd729934a5d6ce86534e8 100644 --- a/connection.go +++ b/connection.go @@ -17,6 +17,7 @@ "github.com/anacrolix/missinggo" "github.com/anacrolix/missinggo/bitmap" "github.com/anacrolix/missinggo/prioritybitmap" + "github.com/anacrolix/missinggo/slices" "github.com/bradfitz/iter" "github.com/anacrolix/torrent/bencode" @@ -675,5 +676,5 @@ lasts := []time.Time{c.lastUsefulChunkReceived} if c.t.seeding() { lasts = append(lasts, c.lastChunkSent) } - return missinggo.Max(time.Time.Before, missinggo.ConvertToSliceOfEmptyInterface(lasts)...).(time.Time) + return missinggo.Max(time.Time.Before, slices.ToEmptyInterface(lasts)...).(time.Time) } diff --git a/metainfo/metainfo.go b/metainfo/metainfo.go index 9e5fddb1ecd9b3e480e4359be1090f67ceb78cd0..f50190eb16c960d2e658f23e0c6b71996862795e 100644 --- a/metainfo/metainfo.go +++ b/metainfo/metainfo.go @@ -11,8 +11,7 @@ "path/filepath" "strings" "time" - "github.com/anacrolix/missinggo" - + "github.com/anacrolix/missinggo/slices" "github.com/anacrolix/torrent/bencode" ) @@ -85,7 +84,7 @@ }) if err != nil { return } - missinggo.SortSlice(info.Files, func(l, r FileInfo) bool { + slices.Sort(info.Files, func(l, r FileInfo) bool { return strings.Join(l.Path, "/") < strings.Join(r.Path, "/") }) err = info.GeneratePieces(func(fi FileInfo) (io.ReadCloser, error) { diff --git a/torrent.go b/torrent.go index af6b2f253763f179a12c0404de90e4cf16fffb4e..179d61eae19323b7195d34961a9f31bc534acdf2 100644 --- a/torrent.go +++ b/torrent.go @@ -18,6 +18,7 @@ "github.com/anacrolix/missinggo/bitmap" "github.com/anacrolix/missinggo/itertools" "github.com/anacrolix/missinggo/perf" "github.com/anacrolix/missinggo/pubsub" + "github.com/anacrolix/missinggo/slices" "github.com/bradfitz/iter" "github.com/anacrolix/torrent/bencode" @@ -442,7 +443,7 @@ fmt.Fprintf(w, "Pending peers: %d\n", len(t.peers)) fmt.Fprintf(w, "Half open: %d\n", len(t.halfOpen)) fmt.Fprintf(w, "Active peers: %d\n", len(t.conns)) - missinggo.SortSlice(t.conns, worseConn) + slices.Sort(t.conns, worseConn) for i, c := range t.conns { fmt.Fprintf(w, "%2d. ", i+1) c.WriteStatus(w, t) @@ -737,7 +738,7 @@ // for the longest. A bad connection is one that usually sends us unwanted // pieces, or has been in worser half of the established connections for more // than a minute. func (t *Torrent) worstBadConn() *connection { - wcs := missinggo.HeapFromSlice(t.worstUnclosedConns(), worseConn) + wcs := slices.AsHeap(t.worstUnclosedConns(), worseConn) for wcs.Len() != 0 { c := heap.Pop(wcs).(*connection) if c.UnwantedChunksReceived >= 6 && c.UnwantedChunksReceived > c.UsefulChunksReceived { @@ -1318,7 +1319,7 @@ t.cl.mu.Lock() defer t.cl.mu.Unlock() oldMax = t.maxEstablishedConns t.maxEstablishedConns = max - wcs := missinggo.HeapFromSlice(append([]*connection(nil), t.conns...), worseConn) + wcs := slices.AsHeap(append([]*connection(nil), t.conns...), worseConn) for len(t.conns) > t.maxEstablishedConns && wcs.Len() > 0 { t.dropConnection(wcs.Pop().(*connection)) }