From 44e4a5b13a5c4ad7ee7522258ffe14467150c6a7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 26 Apr 2019 01:48:40 +0800 Subject: [PATCH] Avoid performance penalty from type erasure On average the affected code path is 0.1% faster and the result binary is 10 KB smaller. --- src/base/settingvalue.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/settingvalue.h b/src/base/settingvalue.h index 5ce8f3d8a..e3ff237c1 100644 --- a/src/base/settingvalue.h +++ b/src/base/settingvalue.h @@ -29,7 +29,6 @@ #ifndef SETTINGVALUE_H #define SETTINGVALUE_H -#include #include #include @@ -41,8 +40,6 @@ template class CachedSettingValue { - using ProxyFunc = std::function; - public: explicit CachedSettingValue(const char *keyName, const T &defaultValue = T()) : m_keyName(QLatin1String(keyName)) @@ -50,8 +47,11 @@ public: { } + // The signature of the ProxyFunc should be equivalent to the following: + // T proxyFunc(const T &a); + template explicit CachedSettingValue(const char *keyName, const T &defaultValue - , const ProxyFunc &proxyFunc) + , ProxyFunc proxyFunc) : m_keyName(QLatin1String(keyName)) , m_value(proxyFunc(loadValue(defaultValue))) {