mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Avoid performance penalty from type erasure
On average the affected code path is 0.1% faster and the result binary is 10 KB smaller.
This commit is contained in:
parent
6435e994f1
commit
44e4a5b13a
@ -29,7 +29,6 @@
|
||||
#ifndef SETTINGVALUE_H
|
||||
#define SETTINGVALUE_H
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#include <QMetaEnum>
|
||||
@ -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:
|
||||
{
|
||||
}
|
||||
|
||||
// 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…
Reference in New Issue
Block a user