mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 13:58:51 +03:00
Speed up piece relevance calculation
For ~800 pieces, this roughly cuts the run time (of this function) in half.
This commit is contained in:
parent
1729b9f29c
commit
ff99e5ac9a
1 changed files with 7 additions and 16 deletions
|
@ -229,24 +229,15 @@ QString PeerInfo::connectionType() const
|
|||
void PeerInfo::calcRelevance(const Torrent *torrent)
|
||||
{
|
||||
const QBitArray allPieces = torrent->pieces();
|
||||
const int localMissing = allPieces.count(false);
|
||||
if (localMissing <= 0)
|
||||
{
|
||||
m_relevance = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const QBitArray peerPieces = pieces();
|
||||
|
||||
int localMissing = 0;
|
||||
int remoteHaves = 0;
|
||||
|
||||
for (int i = 0; i < allPieces.size(); ++i)
|
||||
{
|
||||
if (!allPieces[i])
|
||||
{
|
||||
++localMissing;
|
||||
if (peerPieces[i])
|
||||
++remoteHaves;
|
||||
}
|
||||
}
|
||||
|
||||
if (localMissing == 0)
|
||||
m_relevance = 0.0;
|
||||
else
|
||||
const int remoteHaves = (peerPieces & (~allPieces)).count(true);
|
||||
m_relevance = static_cast<qreal>(remoteHaves) / localMissing;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue