mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-23 01:40:00 +00:00
Optimize conversion of time points from libtorrent to Qt clocks
Some checks failed
CI - File health / Check (push) Waiting to run
CI - macOS / Build (1.2.19, GUI=OFF, 6.7.0) (push) Waiting to run
CI - macOS / Build (1.2.19, GUI=ON, 6.7.0) (push) Waiting to run
CI - macOS / Build (2.0.10, GUI=OFF, 6.7.0) (push) Waiting to run
CI - macOS / Build (2.0.10, GUI=ON, 6.7.0) (push) Waiting to run
CI - Python / Check (push) Waiting to run
CI - Ubuntu / Build (1.2.19, GUI=OFF, 6.5.2) (push) Waiting to run
CI - Ubuntu / Build (1.2.19, GUI=ON, 6.5.2) (push) Waiting to run
CI - Ubuntu / Build (2.0.10, GUI=OFF, 6.5.2) (push) Waiting to run
CI - Ubuntu / Build (2.0.10, GUI=ON, 6.5.2) (push) Waiting to run
CI - WebUI / Check (push) Waiting to run
CI - Windows / Build (1.2.19) (push) Waiting to run
CI - Windows / Build (2.0.10) (push) Waiting to run
Stale bot / stale (push) Has been cancelled
Some checks failed
CI - File health / Check (push) Waiting to run
CI - macOS / Build (1.2.19, GUI=OFF, 6.7.0) (push) Waiting to run
CI - macOS / Build (1.2.19, GUI=ON, 6.7.0) (push) Waiting to run
CI - macOS / Build (2.0.10, GUI=OFF, 6.7.0) (push) Waiting to run
CI - macOS / Build (2.0.10, GUI=ON, 6.7.0) (push) Waiting to run
CI - Python / Check (push) Waiting to run
CI - Ubuntu / Build (1.2.19, GUI=OFF, 6.5.2) (push) Waiting to run
CI - Ubuntu / Build (1.2.19, GUI=ON, 6.5.2) (push) Waiting to run
CI - Ubuntu / Build (2.0.10, GUI=OFF, 6.5.2) (push) Waiting to run
CI - Ubuntu / Build (2.0.10, GUI=ON, 6.5.2) (push) Waiting to run
CI - WebUI / Check (push) Waiting to run
CI - Windows / Build (1.2.19) (push) Waiting to run
CI - Windows / Build (2.0.10) (push) Waiting to run
Stale bot / stale (push) Has been cancelled
Obtain current date time of Qt and libtorrent clocks only once for processing entire current libtorrent alerts bunch. PR #21764.
This commit is contained in:
parent
051d7137ea
commit
75d1ac8889
@ -5504,6 +5504,11 @@ void SessionImpl::setTorrentContentLayout(const TorrentContentLayout value)
|
||||
// Read alerts sent by libtorrent session
|
||||
void SessionImpl::readAlerts()
|
||||
{
|
||||
// cache current datetime of Qt and libtorrent clocks in order
|
||||
// to optimize conversion of time points from lt to Qt clocks
|
||||
m_ltNow = lt::clock_type::now();
|
||||
m_qNow = QDateTime::currentDateTime();
|
||||
|
||||
const std::vector<lt::alert *> alerts = getPendingAlerts();
|
||||
|
||||
Q_ASSERT(m_loadedTorrents.isEmpty());
|
||||
@ -6373,3 +6378,9 @@ void SessionImpl::handleRemovedTorrent(const TorrentID &torrentID, const QString
|
||||
|
||||
m_removingTorrents.erase(removingTorrentDataIter);
|
||||
}
|
||||
|
||||
QDateTime SessionImpl::fromLTTimePoint32(const libtorrent::time_point32 &timePoint) const
|
||||
{
|
||||
const auto secsSinceNow = lt::duration_cast<lt::seconds>(timePoint - m_ltNow + lt::milliseconds(500)).count();
|
||||
return m_qNow.addSecs(secsSinceNow);
|
||||
}
|
||||
|
@ -476,6 +476,8 @@ namespace BitTorrent
|
||||
void addMappedPorts(const QSet<quint16> &ports);
|
||||
void removeMappedPorts(const QSet<quint16> &ports);
|
||||
|
||||
QDateTime fromLTTimePoint32(const lt::time_point32 &timePoint) const;
|
||||
|
||||
template <typename Func>
|
||||
void invoke(Func &&func)
|
||||
{
|
||||
@ -826,6 +828,9 @@ namespace BitTorrent
|
||||
|
||||
QList<TorrentImpl *> m_pendingFinishedTorrents;
|
||||
|
||||
QDateTime m_qNow;
|
||||
lt::clock_type::time_point m_ltNow;
|
||||
|
||||
friend void Session::initInstance();
|
||||
friend void Session::freeInstance();
|
||||
friend Session *Session::instance();
|
||||
|
@ -92,22 +92,15 @@ namespace
|
||||
return entry;
|
||||
}
|
||||
|
||||
QDateTime fromLTTimePoint32(const lt::time_point32 &timePoint)
|
||||
{
|
||||
const auto ltNow = lt::clock_type::now();
|
||||
const auto qNow = QDateTime::currentDateTime();
|
||||
const auto secsSinceNow = lt::duration_cast<lt::seconds>(timePoint - ltNow + lt::milliseconds(500)).count();
|
||||
|
||||
return qNow.addSecs(secsSinceNow);
|
||||
}
|
||||
|
||||
QString toString(const lt::tcp::endpoint <TCPEndpoint)
|
||||
{
|
||||
return QString::fromStdString((std::stringstream() << ltTCPEndpoint).str());
|
||||
}
|
||||
|
||||
template <typename FromLTTimePoint32Func>
|
||||
void updateTrackerEntryStatus(TrackerEntryStatus &trackerEntryStatus, const lt::announce_entry &nativeEntry
|
||||
, const QSet<int> &btProtocols, const QHash<lt::tcp::endpoint, QMap<int, int>> &updateInfo)
|
||||
, const QSet<int> &btProtocols, const QHash<lt::tcp::endpoint, QMap<int, int>> &updateInfo
|
||||
, const FromLTTimePoint32Func &fromLTTimePoint32)
|
||||
{
|
||||
Q_ASSERT(trackerEntryStatus.url == QString::fromStdString(nativeEntry.url));
|
||||
|
||||
@ -1769,7 +1762,13 @@ TrackerEntryStatus TorrentImpl::updateTrackerEntryStatus(const lt::announce_entr
|
||||
#else
|
||||
const QSet<int> btProtocols {1};
|
||||
#endif
|
||||
::updateTrackerEntryStatus(*it, announceEntry, btProtocols, updateInfo);
|
||||
|
||||
const auto fromLTTimePoint32 = [this](const lt::time_point32 &timePoint)
|
||||
{
|
||||
return m_session->fromLTTimePoint32(timePoint);
|
||||
};
|
||||
::updateTrackerEntryStatus(*it, announceEntry, btProtocols, updateInfo, fromLTTimePoint32);
|
||||
|
||||
return *it;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user