Browse Source

Avoid performance penalty from type erasure

On average the affected code path is 0.1% faster and the result binary
is 10 KB smaller.
adaptive-webui-19844
Chocobo1 6 years ago
parent
commit
44e4a5b13a
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 8
      src/base/settingvalue.h

8
src/base/settingvalue.h

@ -29,7 +29,6 @@ @@ -29,7 +29,6 @@
#ifndef SETTINGVALUE_H
#define SETTINGVALUE_H
#include <functional>
#include <type_traits>
#include <QMetaEnum>
@ -41,8 +40,6 @@ @@ -41,8 +40,6 @@
template <typename T>
class CachedSettingValue
{
using ProxyFunc = std::function<T (const T&)>;
public:
explicit CachedSettingValue(const char *keyName, const T &defaultValue = T())
: m_keyName(QLatin1String(keyName))
@ -50,8 +47,11 @@ public: @@ -50,8 +47,11 @@ public:
{
}
// The signature of the ProxyFunc should be equivalent to the following:
// T proxyFunc(const T &a);
template <typename ProxyFunc>
explicit CachedSettingValue(const char *keyName, const T &defaultValue
, const ProxyFunc &proxyFunc)
, ProxyFunc proxyFunc)
: m_keyName(QLatin1String(keyName))
, m_value(proxyFunc(loadValue(defaultValue)))
{

Loading…
Cancel
Save