mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-23 17:56:50 +03: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:
parent
3da9444688
commit
4527536858
1 changed files with 10 additions and 1 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue