Optimize Peer.peerHasWantedPieces
This commit is contained in:
parent
5e8f61abb5
commit
198a938700
13
peerconn.go
13
peerconn.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue