From 53992bf0d5c76f607c43511c4829b721a32f7417 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 24 Jan 2022 13:44:49 +0800 Subject: [PATCH] Initialize class variable in initializer list --- src/base/bittorrent/peerinfo.cpp | 11 ++++------- src/base/bittorrent/peerinfo.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 835c85c08..291459434 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -39,8 +39,8 @@ using namespace BitTorrent; PeerInfo::PeerInfo(const Torrent *torrent, const lt::peer_info &nativeInfo) : m_nativeInfo(nativeInfo) + , m_relevance(calcRelevance(torrent)) { - calcRelevance(torrent); determineFlags(); } @@ -226,19 +226,16 @@ QString PeerInfo::connectionType() const : QLatin1String {"Web"}; } -void PeerInfo::calcRelevance(const Torrent *torrent) +qreal PeerInfo::calcRelevance(const Torrent *torrent) const { const QBitArray allPieces = torrent->pieces(); const int localMissing = allPieces.count(false); if (localMissing <= 0) - { - m_relevance = 0; - return; - } + return 0; const QBitArray peerPieces = pieces(); const int remoteHaves = (peerPieces & (~allPieces)).count(true); - m_relevance = static_cast(remoteHaves) / localMissing; + return static_cast(remoteHaves) / localMissing; } qreal PeerInfo::relevance() const diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index bfa5f9b2e..f7f51d177 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -92,7 +92,7 @@ namespace BitTorrent int downloadingPieceIndex() const; private: - void calcRelevance(const Torrent *torrent); + qreal calcRelevance(const Torrent *torrent) const; void determineFlags(); lt::peer_info m_nativeInfo = {};