mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-20 15:37:26 -06:00
Optimize converting TCP endpoints to strings
There may be quite a few endpoint names (one for each available network card), and they usually remain unchanged throughout the session, while previously producing such names was performed every time they were accessed. Now they are retrieved from the cache. PR #21770.
This commit is contained in:
committed by
GitHub
parent
3da9444688
commit
4527536858
@@ -49,6 +49,7 @@
|
||||
|
||||
#include <QtSystemDetection>
|
||||
#include <QByteArray>
|
||||
#include <QCache>
|
||||
#include <QDebug>
|
||||
#include <QPointer>
|
||||
#include <QSet>
|
||||
@@ -94,7 +95,15 @@ namespace
|
||||
|
||||
QString toString(const lt::tcp::endpoint <TCPEndpoint)
|
||||
{
|
||||
return QString::fromStdString((std::stringstream() << ltTCPEndpoint).str());
|
||||
static QCache<lt::tcp::endpoint, QString> cache;
|
||||
|
||||
if (const QString *endpointName = cache.object(ltTCPEndpoint))
|
||||
return *endpointName;
|
||||
|
||||
const std::string tmp = (std::ostringstream() << ltTCPEndpoint).str();
|
||||
const auto endpointName = QString::fromLatin1(tmp.c_str(), tmp.size());
|
||||
cache.insert(ltTCPEndpoint, new QString(endpointName));
|
||||
return endpointName;
|
||||
}
|
||||
|
||||
template <typename FromLTTimePoint32Func>
|
||||
|
||||
Reference in New Issue
Block a user