Simplify PIece.iterUndirtiedChunks
This commit is contained in:
parent
377eabd7b4
commit
72b0fee1eb
7
piece.go
7
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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue