mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07: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
10499dffe9
commit
f2b2a2b034
1 changed files with 10 additions and 1 deletions
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
#include <QtSystemDetection>
|
#include <QtSystemDetection>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QCache>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
@ -94,7 +95,15 @@ namespace
|
||||||
|
|
||||||
QString toString(const lt::tcp::endpoint <TCPEndpoint)
|
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>
|
template <typename FromLTTimePoint32Func>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue