Use new missinggo iterator style, and speed up torrent.connHasWantedPieces()
This commit is contained in:
parent
814daf6420
commit
77d6e9e5cb
|
@ -13,7 +13,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/missinggo"
|
"github.com/anacrolix/missinggo"
|
||||||
"github.com/anacrolix/missinggo/itertools"
|
|
||||||
"github.com/anacrolix/missinggo/prioritybitmap"
|
"github.com/anacrolix/missinggo/prioritybitmap"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent/bencode"
|
"github.com/anacrolix/torrent/bencode"
|
||||||
|
@ -560,8 +559,8 @@ func (c *connection) updateRequests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *connection) fillRequests() {
|
func (c *connection) fillRequests() {
|
||||||
itertools.ForIterable(&c.pieceRequestOrder, func(_piece interface{}) (more bool) {
|
c.pieceRequestOrder.IterTyped(func(piece int) (more bool) {
|
||||||
return c.requestPiecePendingChunks(_piece.(int))
|
return c.requestPiecePendingChunks(piece)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
torrent.go
20
torrent.go
|
@ -14,7 +14,6 @@ import (
|
||||||
|
|
||||||
"github.com/anacrolix/missinggo"
|
"github.com/anacrolix/missinggo"
|
||||||
"github.com/anacrolix/missinggo/bitmap"
|
"github.com/anacrolix/missinggo/bitmap"
|
||||||
"github.com/anacrolix/missinggo/itertools"
|
|
||||||
"github.com/anacrolix/missinggo/perf"
|
"github.com/anacrolix/missinggo/perf"
|
||||||
"github.com/anacrolix/missinggo/pubsub"
|
"github.com/anacrolix/missinggo/pubsub"
|
||||||
"github.com/bradfitz/iter"
|
"github.com/bradfitz/iter"
|
||||||
|
@ -770,20 +769,7 @@ func (t *torrent) forNeededPieces(f func(piece int) (more bool)) (all bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) connHasWantedPieces(c *connection) bool {
|
func (t *torrent) connHasWantedPieces(c *connection) bool {
|
||||||
for it := t.pendingPieces.IterTyped(); it.Next(); {
|
return !c.pieceRequestOrder.IsEmpty()
|
||||||
if c.PeerHasPiece(it.ValueInt()) {
|
|
||||||
it.Stop()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !t.forReaderOffsetPieces(func(begin, end int) (again bool) {
|
|
||||||
for i := begin; i < end; i++ {
|
|
||||||
if c.PeerHasPiece(i) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *torrent) extentPieces(off, _len int64) (pieces []int) {
|
func (t *torrent) extentPieces(off, _len int64) (pieces []int) {
|
||||||
|
@ -872,8 +858,8 @@ func (t *torrent) updatePiecePriority(piece int) bool {
|
||||||
|
|
||||||
func (t *torrent) updatePiecePriorities() {
|
func (t *torrent) updatePiecePriorities() {
|
||||||
newPrios := make([]piecePriority, t.numPieces())
|
newPrios := make([]piecePriority, t.numPieces())
|
||||||
itertools.ForIterable(&t.pendingPieces, func(value interface{}) (next bool) {
|
t.pendingPieces.IterTyped(func(piece int) (more bool) {
|
||||||
newPrios[value.(int)] = PiecePriorityNormal
|
newPrios[piece] = PiecePriorityNormal
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
t.forReaderOffsetPieces(func(begin, end int) (next bool) {
|
t.forReaderOffsetPieces(func(begin, end int) (next bool) {
|
||||||
|
|
Loading…
Reference in New Issue