]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Use new missinggo iterator style, and speed up torrent.connHasWantedPieces()
authorMatt Joiner <anacrolix@gmail.com>
Sat, 6 Feb 2016 14:22:31 +0000 (01:22 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 6 Feb 2016 14:22:31 +0000 (01:22 +1100)
connection.go
torrent.go

index 9050c4cfa079997ac9a1f8d6eea0169f33f0af14..2340e5e245b9d797fb1a8938b0fd412a2db17079 100644 (file)
@@ -13,7 +13,6 @@ import (
        "time"
 
        "github.com/anacrolix/missinggo"
-       "github.com/anacrolix/missinggo/itertools"
        "github.com/anacrolix/missinggo/prioritybitmap"
 
        "github.com/anacrolix/torrent/bencode"
@@ -560,8 +559,8 @@ func (c *connection) updateRequests() {
 }
 
 func (c *connection) fillRequests() {
-       itertools.ForIterable(&c.pieceRequestOrder, func(_piece interface{}) (more bool) {
-               return c.requestPiecePendingChunks(_piece.(int))
+       c.pieceRequestOrder.IterTyped(func(piece int) (more bool) {
+               return c.requestPiecePendingChunks(piece)
        })
 }
 
index f58a5d683b3766638a18cc0bbaa90855c077d069..82d34fd39599e18b5a08e4d6a57cc163db0fe7e3 100644 (file)
@@ -14,7 +14,6 @@ import (
 
        "github.com/anacrolix/missinggo"
        "github.com/anacrolix/missinggo/bitmap"
-       "github.com/anacrolix/missinggo/itertools"
        "github.com/anacrolix/missinggo/perf"
        "github.com/anacrolix/missinggo/pubsub"
        "github.com/bradfitz/iter"
@@ -770,20 +769,7 @@ func (t *torrent) forNeededPieces(f func(piece int) (more bool)) (all bool) {
 }
 
 func (t *torrent) connHasWantedPieces(c *connection) bool {
-       for it := t.pendingPieces.IterTyped(); it.Next(); {
-               if c.PeerHasPiece(it.ValueInt()) {
-                       it.Stop()
-                       return true
-               }
-       }
-       return !t.forReaderOffsetPieces(func(begin, end int) (again bool) {
-               for i := begin; i < end; i++ {
-                       if c.PeerHasPiece(i) {
-                               return false
-                       }
-               }
-               return true
-       })
+       return !c.pieceRequestOrder.IsEmpty()
 }
 
 func (t *torrent) extentPieces(off, _len int64) (pieces []int) {
@@ -872,8 +858,8 @@ func (t *torrent) updatePiecePriority(piece int) bool {
 
 func (t *torrent) updatePiecePriorities() {
        newPrios := make([]piecePriority, t.numPieces())
-       itertools.ForIterable(&t.pendingPieces, func(value interface{}) (next bool) {
-               newPrios[value.(int)] = PiecePriorityNormal
+       t.pendingPieces.IterTyped(func(piece int) (more bool) {
+               newPrios[piece] = PiecePriorityNormal
                return true
        })
        t.forReaderOffsetPieces(func(begin, end int) (next bool) {