]> Sergey Matveev's repositories - btrtrc.git/commitdiff
New slices package
authorMatt Joiner <anacrolix@gmail.com>
Tue, 12 Jul 2016 06:40:14 +0000 (16:40 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 12 Jul 2016 06:40:14 +0000 (16:40 +1000)
client.go
connection.go
metainfo/metainfo.go
torrent.go

index e5cdf0c2ae367eeb7aee0d401b16aa22708f0da8..1491b25d547841e9075d062c921678467f283711 100644 (file)
--- a/client.go
+++ b/client.go
@@ -21,6 +21,7 @@ import (
        "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) AddMagnet(uri string) (T *Torrent, err error) {
 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
 }
index a58647ad628b4589620dedebf8c19c0de5fede93..80ef299997e396decbfbd729934a5d6ce86534e8 100644 (file)
@@ -17,6 +17,7 @@ import (
        "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 @@ func (c *connection) lastHelpful() time.Time {
        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)
 }
index 9e5fddb1ecd9b3e480e4359be1090f67ceb78cd0..f50190eb16c960d2e658f23e0c6b71996862795e 100644 (file)
@@ -11,8 +11,7 @@ import (
        "strings"
        "time"
 
-       "github.com/anacrolix/missinggo"
-
+       "github.com/anacrolix/missinggo/slices"
        "github.com/anacrolix/torrent/bencode"
 )
 
@@ -85,7 +84,7 @@ func (info *Info) BuildFromFilePath(root string) (err error) {
        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) {
index af6b2f253763f179a12c0404de90e4cf16fffb4e..179d61eae19323b7195d34961a9f31bc534acdf2 100644 (file)
@@ -18,6 +18,7 @@ import (
        "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 @@ func (t *Torrent) writeStatus(w io.Writer, cl *Client) {
        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 @@ func (t *Torrent) extentPieces(off, _len int64) (pieces []int) {
 // 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 @@ func (t *Torrent) SetMaxEstablishedConns(max int) (oldMax int) {
        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))
        }