mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07: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
1 changed files with 4 additions and 4 deletions
|
@ -29,7 +29,6 @@
|
||||||
#ifndef SETTINGVALUE_H
|
#ifndef SETTINGVALUE_H
|
||||||
#define SETTINGVALUE_H
|
#define SETTINGVALUE_H
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
|
@ -41,8 +40,6 @@
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class CachedSettingValue
|
class CachedSettingValue
|
||||||
{
|
{
|
||||||
using ProxyFunc = std::function<T (const T&)>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CachedSettingValue(const char *keyName, const T &defaultValue = T())
|
explicit CachedSettingValue(const char *keyName, const T &defaultValue = T())
|
||||||
: m_keyName(QLatin1String(keyName))
|
: 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
|
explicit CachedSettingValue(const char *keyName, const T &defaultValue
|
||||||
, const ProxyFunc &proxyFunc)
|
, ProxyFunc proxyFunc)
|
||||||
: m_keyName(QLatin1String(keyName))
|
: m_keyName(QLatin1String(keyName))
|
||||||
, m_value(proxyFunc(loadValue(defaultValue)))
|
, m_value(proxyFunc(loadValue(defaultValue)))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue