Speed up piece relevance calculation

For ~800 pieces, this roughly cuts the run time (of this function) in
half.
This commit is contained in:
Chocobo1 2022-01-24 10:41:25 +08:00
parent 1729b9f29c
commit ff99e5ac9a
No known key found for this signature in database
GPG key ID: 210D9C873253A68C

View file

@ -229,25 +229,16 @@ QString PeerInfo::connectionType() const
void PeerInfo::calcRelevance(const Torrent *torrent)
{
const QBitArray allPieces = torrent->pieces();
const QBitArray peerPieces = pieces();
int localMissing = 0;
int remoteHaves = 0;
for (int i = 0; i < allPieces.size(); ++i)
const int localMissing = allPieces.count(false);
if (localMissing <= 0)
{
if (!allPieces[i])
{
++localMissing;
if (peerPieces[i])
++remoteHaves;
}
m_relevance = 0;
return;
}
if (localMissing == 0)
m_relevance = 0.0;
else
m_relevance = static_cast<qreal>(remoteHaves) / localMissing;
const QBitArray peerPieces = pieces();
const int remoteHaves = (peerPieces & (~allPieces)).count(true);
m_relevance = static_cast<qreal>(remoteHaves) / localMissing;
}
qreal PeerInfo::relevance() const