Browse Source

Speed up piece relevance calculation

For ~800 pieces, this roughly cuts the run time (of this function) in
half.
adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
ff99e5ac9a
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 21
      src/base/bittorrent/peerinfo.cpp

21
src/base/bittorrent/peerinfo.cpp

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

Loading…
Cancel
Save