func (t Torrent) DownloadAll() {
t.cl.mu.Lock()
defer t.cl.mu.Unlock()
- for i := range iter.N(t.torrent.Info.NumPieces()) {
- t.torrent.pendPiece(i, t.cl)
- }
+ t.torrent.pendPieceRange(0, t.torrent.numPieces())
}
// Returns nil metainfo if it isn't in the cache. Checks that the retrieved
return
}
-func (t *torrent) pendPiece(piece int, cl *Client) {
+func (t *torrent) pendPiece(piece int) {
if t.pendingPieces.Contains(piece) {
return
}
return
}
-func (t *torrent) pendPieces(pend *bitmap.Bitmap) {
- t.pendingPieces.Union(pend)
- t.updatePiecePriorities()
-}
-
func (t *torrent) unpendPieces(unpend *bitmap.Bitmap) {
t.pendingPieces.Sub(unpend)
t.updatePiecePriorities()
}
func (t *torrent) pendPieceRange(begin, end int) {
- var bm bitmap.Bitmap
- bm.AddRange(begin, end)
- t.pendPieces(&bm)
+ for i := begin; i < end; i++ {
+ t.pendPiece(i)
+ }
}
func (t *torrent) unpendPieceRange(begin, end int) {