From 72b0fee1eb16361874057c0b943bcbc7deb0e8ae Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 11 Sep 2021 21:17:47 +1000 Subject: [PATCH] Simplify PIece.iterUndirtiedChunks --- piece.go | 7 ++----- requesting.go | 20 +++++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/piece.go b/piece.go index e1b6ff90..c7944697 100644 --- a/piece.go +++ b/piece.go @@ -237,14 +237,11 @@ func (p *Piece) State() PieceState { return p.t.PieceState(p.index) } -func (p *Piece) iterUndirtiedChunks(f func(cs ChunkSpec) bool) bool { +func (p *Piece) iterUndirtiedChunks(f func(cs ChunkSpec)) { for i := pp.Integer(0); i < p.numChunks(); i++ { if p.chunkIndexDirty(i) { continue } - if !f(p.chunkIndexSpec(i)) { - return false - } + f(p.chunkIndexSpec(i)) } - return true } diff --git a/requesting.go b/requesting.go index 6a10e0a9..829470f7 100644 --- a/requesting.go +++ b/requesting.go @@ -8,7 +8,6 @@ import ( "github.com/anacrolix/chansync" request_strategy "github.com/anacrolix/torrent/request-strategy" - "github.com/anacrolix/torrent/types" ) func (cl *Client) requester() { @@ -50,18 +49,13 @@ func (cl *Client) doRequests() { for i := range t.pieces { p := &t.pieces[i] rst.Pieces = append(rst.Pieces, request_strategy.Piece{ - Request: !t.ignorePieceForRequests(i), - Priority: p.purePriority(), - Partial: t.piecePartiallyDownloaded(i), - Availability: p.availability, - Length: int64(p.length()), - NumPendingChunks: int(t.pieceNumPendingChunks(i)), - IterPendingChunks: func(f func(types.ChunkSpec)) { - p.iterUndirtiedChunks(func(cs ChunkSpec) bool { - f(cs) - return true - }) - }, + Request: !t.ignorePieceForRequests(i), + Priority: p.purePriority(), + Partial: t.piecePartiallyDownloaded(i), + Availability: p.availability, + Length: int64(p.length()), + NumPendingChunks: int(t.pieceNumPendingChunks(i)), + IterPendingChunks: p.iterUndirtiedChunks, }) } t.iterPeers(func(p *Peer) { -- 2.48.1