mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 06:01:33 -06:00
Avoid heavy weight function object
Also, by switching to template we can avoid the cost of converting to some specific type and perfectly forward the parameter to the final function. PR #21572.
This commit is contained in:
@@ -35,8 +35,6 @@
|
||||
#include <QMutexLocker>
|
||||
#include <QThread>
|
||||
|
||||
#include "base/global.h"
|
||||
|
||||
const int TORRENTIDLIST_TYPEID = qRegisterMetaType<QList<BitTorrent::TorrentID>>();
|
||||
|
||||
BitTorrent::ResumeDataStorage::ResumeDataStorage(const Path &path, QObject *parent)
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
#include <QThreadPool>
|
||||
#include <QTimer>
|
||||
#include <QUuid>
|
||||
|
||||
@@ -3013,11 +3012,6 @@ void SessionImpl::removeMappedPorts(const QSet<quint16> &ports)
|
||||
});
|
||||
}
|
||||
|
||||
void SessionImpl::invokeAsync(std::function<void ()> func)
|
||||
{
|
||||
m_asyncWorker->start(std::move(func));
|
||||
}
|
||||
|
||||
// Add a torrent to libtorrent session in hidden mode
|
||||
// and force it to download its metadata
|
||||
bool SessionImpl::downloadMetadata(const TorrentDescriptor &torrentDescr)
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <QMap>
|
||||
#include <QPointer>
|
||||
#include <QSet>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include "base/path.h"
|
||||
#include "base/settingvalue.h"
|
||||
@@ -57,7 +58,6 @@
|
||||
#include "trackerentrystatus.h"
|
||||
|
||||
class QString;
|
||||
class QThreadPool;
|
||||
class QTimer;
|
||||
class QUrl;
|
||||
|
||||
@@ -482,7 +482,11 @@ namespace BitTorrent
|
||||
QMetaObject::invokeMethod(this, std::forward<Func>(func), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void invokeAsync(std::function<void ()> func);
|
||||
template <typename Func>
|
||||
void invokeAsync(Func &&func)
|
||||
{
|
||||
m_asyncWorker->start(std::forward<Func>(func));
|
||||
}
|
||||
|
||||
signals:
|
||||
void addTorrentAlertsReceived(qsizetype count);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "torrentscontroller.h"
|
||||
|
||||
#include <concepts>
|
||||
#include <functional>
|
||||
|
||||
#include <QBitArray>
|
||||
@@ -135,7 +136,9 @@ namespace
|
||||
|
||||
const QSet<QString> SUPPORTED_WEB_SEED_SCHEMES {u"http"_s, u"https"_s, u"ftp"_s};
|
||||
|
||||
void applyToTorrents(const QStringList &idList, const std::function<void (BitTorrent::Torrent *torrent)> &func)
|
||||
template <typename Func>
|
||||
void applyToTorrents(const QStringList &idList, Func func)
|
||||
requires std::invocable<Func, BitTorrent::Torrent *>
|
||||
{
|
||||
if ((idList.size() == 1) && (idList[0] == u"all"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user