From 775b38079f87c8457f64a4c65cc35ad7122ff022 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 29 Apr 2024 13:05:05 +0800 Subject: [PATCH] Avoid repetitive function calls PR #20764. --- src/base/torrentfilter.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/base/torrentfilter.cpp b/src/base/torrentfilter.cpp index 8a2331eb1..7ad8cf112 100644 --- a/src/base/torrentfilter.cpp +++ b/src/base/torrentfilter.cpp @@ -156,10 +156,11 @@ bool TorrentFilter::match(const Torrent *const torrent) const bool TorrentFilter::matchState(const BitTorrent::Torrent *const torrent) const { + const BitTorrent::TorrentState state = torrent->state(); + switch (m_type) { case All: - default: return true; case Downloading: return torrent->isDownloading(); @@ -176,20 +177,23 @@ bool TorrentFilter::matchState(const BitTorrent::Torrent *const torrent) const case Inactive: return torrent->isInactive(); case Stalled: - return (torrent->state() == BitTorrent::TorrentState::StalledUploading) - || (torrent->state() == BitTorrent::TorrentState::StalledDownloading); + return (state == BitTorrent::TorrentState::StalledUploading) + || (state == BitTorrent::TorrentState::StalledDownloading); case StalledUploading: - return torrent->state() == BitTorrent::TorrentState::StalledUploading; + return state == BitTorrent::TorrentState::StalledUploading; case StalledDownloading: - return torrent->state() == BitTorrent::TorrentState::StalledDownloading; + return state == BitTorrent::TorrentState::StalledDownloading; case Checking: - return (torrent->state() == BitTorrent::TorrentState::CheckingUploading) - || (torrent->state() == BitTorrent::TorrentState::CheckingDownloading) - || (torrent->state() == BitTorrent::TorrentState::CheckingResumeData); + return (state == BitTorrent::TorrentState::CheckingUploading) + || (state == BitTorrent::TorrentState::CheckingDownloading) + || (state == BitTorrent::TorrentState::CheckingResumeData); case Moving: return torrent->isMoving(); case Errored: return torrent->isErrored(); + default: + Q_ASSERT(false); + return false; } }