]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Don't randomize chunk order for requestStrategy 3
authorMatt Joiner <anacrolix@gmail.com>
Tue, 17 Jul 2018 05:08:46 +0000 (15:08 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 17 Jul 2018 05:08:46 +0000 (15:08 +1000)
This should also reduce a lot of allocation.

connection.go

index d1aa9fcbebf2ac93501d49e87d6d8d4d0b4497b4..56a0ee5b9c72bbbb0c91b56bf4eb10426ee7f7ce 100644 (file)
@@ -789,6 +789,17 @@ func (cn *connection) iterPendingRequests(piece pieceIndex, f func(request) bool
 }
 
 func iterUndirtiedChunks(piece pieceIndex, t *Torrent, f func(chunkSpec) bool) bool {
+       p := &t.pieces[piece]
+       if t.requestStrategy == 3 {
+               for i := pp.Integer(0); i < p.numChunks(); i++ {
+                       if !p.dirtyChunks.Get(bitmap.BitIndex(i)) {
+                               if !f(t.chunkIndexSpec(i, piece)) {
+                                       return false
+                               }
+                       }
+               }
+               return true
+       }
        chunkIndices := t.pieces[piece].undirtiedChunkIndices().ToSortedSlice()
        // TODO: Use "math/rand".Shuffle >= Go 1.10
        return iter.ForPerm(len(chunkIndices), func(i int) bool {