Ref T184 Cache the result of QHostInfo::localHostName as it is expensive to call.

This commit is contained in:
Mathew Sutcliffe
2017-11-08 19:00:36 +00:00
parent 878498cc9d
commit cd13d18b00

View File

@@ -14,13 +14,20 @@
#include <QHostInfo>
#include <QStringBuilder>
//! \private
const QString &cachedLocalHostName()
{
static const QString hostName = QHostInfo::localHostName();
return hostName;
}
namespace BlackMisc
{
CIdentifier::CIdentifier(const QString &name)
: ITimestampBased(QDateTime::currentMSecsSinceEpoch()),
m_name(name.trimmed()),
m_machineIdBase64(QDBusConnection::localMachineId().toBase64()),
m_machineName(QHostInfo::localHostName()),
m_machineName(cachedLocalHostName()),
m_processName(QCoreApplication::applicationName()),
m_processId(QCoreApplication::applicationPid())
{ }