From: Matt Joiner Date: Tue, 17 Jul 2018 05:08:46 +0000 (+1000) Subject: Don't randomize chunk order for requestStrategy 3 X-Git-Tag: v1.0.0~73 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=216cb7e356870195f485a9a95c98fc6e94a64908;p=btrtrc.git Don't randomize chunk order for requestStrategy 3 This should also reduce a lot of allocation. --- 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 {