if !t.haveInfo() {
return true
}
- for i := range t.pendingPieces {
- if t.wantPiece(i) {
+ for i := t.pendingPieces.Iter(); i.Next(); {
+ if t.wantPiece(i.Value()) {
return true
}
}
}
func (me *Client) onCompletedPiece(t *torrent, piece int) {
- delete(t.pendingPieces, piece)
+ t.pendingPieces.Remove(piece)
for _, conn := range t.Conns {
conn.Have(piece)
for r := range conn.Requests {
"time"
"github.com/anacrolix/missinggo"
+ "github.com/anacrolix/missinggo/bitmap"
"github.com/anacrolix/missinggo/perf"
"github.com/anacrolix/missinggo/pubsub"
"github.com/bradfitz/iter"
readers map[*Reader]struct{}
- pendingPieces map[int]struct{}
+ pendingPieces *bitmap.Bitmap
}
var (
if t.pieceComplete(index) {
return false
}
- if _, ok := t.pendingPieces[index]; ok {
+ if t.pendingPieces.Contains(index) {
return true
}
return !t.forReaderOffsetPieces(func(begin, end int) bool {
}
func (t *torrent) connHasWantedPieces(c *connection) bool {
- for i := range t.pendingPieces {
- if c.PeerHasPiece(i) {
+ for it := t.pendingPieces.Iter(); it.Next(); {
+ if c.PeerHasPiece(it.Value()) {
return true
}
}
if t.pieceComplete(piece) {
return
}
- if _, ok := t.pendingPieces[piece]; ok {
+ if t.pendingPieces.Contains(piece) {
ret = PiecePriorityNormal
}
raiseRet := func(prio piecePriority) {
func (t *torrent) pendPiece(piece int, cl *Client) {
if t.pendingPieces == nil {
- t.pendingPieces = make(map[int]struct{}, t.Info.NumPieces())
+ t.pendingPieces = bitmap.New()
}
- if _, ok := t.pendingPieces[piece]; ok {
+ if t.pendingPieces.Contains(piece) {
return
}
if t.havePiece(piece) {
return
}
- t.pendingPieces[piece] = struct{}{}
+ t.pendingPieces.Add(piece)
for _, c := range t.Conns {
if !c.PeerHasPiece(piece) {
continue