From 216cb7e356870195f485a9a95c98fc6e94a64908 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 17 Jul 2018 15:08:46 +1000 Subject: [PATCH] Don't randomize chunk order for requestStrategy 3 This should also reduce a lot of allocation. --- connection.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/connection.go b/connection.go index d1aa9fcb..56a0ee5b 100644 --- a/connection.go +++ b/connection.go @@ -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 { -- 2.48.1