mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 14:08:03 -06:00
Avoid duplicate lookup
In C++20 `std::views::transform()` followed by `std::views::filter()` has a nasty effect of invoking transformation function twice. Note that there will be a `std::views::cache_latest()` in C++26 to address this issue. Ref: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2760r1.html#cache_last https://stackoverflow.com/questions/64199664/why-c-ranges-transform-filter-calls-transform-twice-for-values-that-match PR #23343.
This commit is contained in:
@@ -5923,12 +5923,15 @@ TorrentImpl *SessionImpl::getTorrent(const lt::torrent_handle &nativeHandle) con
|
|||||||
|
|
||||||
QList<TorrentImpl *> SessionImpl::getQueuedTorrentsByID(const QList<TorrentID> &torrentIDs) const
|
QList<TorrentImpl *> SessionImpl::getQueuedTorrentsByID(const QList<TorrentID> &torrentIDs) const
|
||||||
{
|
{
|
||||||
auto torrents = torrentIDs
|
QList<TorrentImpl *> queuedTorrents;
|
||||||
| std::views::transform([this](const TorrentID &torrentID) { return m_torrents.value(torrentID); })
|
queuedTorrents.reserve(torrentIDs.size());
|
||||||
| std::views::filter([](const TorrentImpl *torrent) { return torrent && (torrent->queuePosition() >= 0); });
|
for (const TorrentID &torrentID : torrentIDs)
|
||||||
|
{
|
||||||
QList<TorrentImpl *> queuedTorrents = {torrents.begin(), torrents.end()};
|
TorrentImpl *torrent = m_torrents.value(torrentID);
|
||||||
std::ranges::sort(queuedTorrents, std::less<>(), &TorrentImpl::queuePosition);
|
if (torrent && (torrent->queuePosition() >= 0))
|
||||||
|
queuedTorrents.push_back(torrent);
|
||||||
|
}
|
||||||
|
std::ranges::sort(queuedTorrents, std::less(), &TorrentImpl::queuePosition);
|
||||||
return queuedTorrents;
|
return queuedTorrents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user