Optimize Peer.peerHasWantedPieces

This commit is contained in:
Matt Joiner 2021-10-11 15:46:40 +11:00
parent 5e8f61abb5
commit 198a938700
1 changed files with 9 additions and 4 deletions

View File

@ -1425,10 +1425,15 @@ func (cn *Peer) netGoodPiecesDirtied() int64 {
}
func (c *Peer) peerHasWantedPieces() bool {
// TODO: Can this be done just with AndCardinality?
missingPeerHas := c.newPeerPieces()
missingPeerHas.AndNot(&c.t._completedPieces)
return !missingPeerHas.IsEmpty()
if c.peerSentHaveAll {
return !c.t.haveAllPieces()
}
if !c.t.haveInfo() {
return c._peerPieces.GetCardinality() != 0
}
return c._peerPieces.Intersects(
roaring.FlipInt(&c.t._completedPieces, 0, c.t.numPieces()),
)
}
func (c *Peer) deleteRequest(r RequestIndex) bool {