Optimize conversion of time points from libtorrent to Qt clocks

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:
Vladimir Golovnev
2024-11-05 16:43:43 +03:00
committed by GitHub
parent 051d7137ea
commit 75d1ac8889
3 changed files with 26 additions and 11 deletions

View File

@@ -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 &ltTCPEndpoint)
{
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;
}