Browse Source

Avoid double lookups

adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
daf52a2610
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 15
      src/base/settingsstorage.cpp
  2. 3
      src/base/settingvalue.h

15
src/base/settingsstorage.cpp

@ -202,17 +202,19 @@ bool SettingsStorage::save() @@ -202,17 +202,19 @@ bool SettingsStorage::save()
QVariant SettingsStorage::loadValue(const QString &key, const QVariant &defaultValue) const
{
QReadLocker locker(&m_lock);
const QReadLocker locker(&m_lock);
return m_data.value(mapKey(key), defaultValue);
}
void SettingsStorage::storeValue(const QString &key, const QVariant &value)
{
const QString realKey = mapKey(key);
QWriteLocker locker(&m_lock);
if (m_data.value(realKey) != value) {
const QWriteLocker locker(&m_lock);
QVariant &currentValue = m_data[realKey];
if (currentValue != value) {
m_dirty = true;
m_data.insert(realKey, value);
currentValue = value;
m_timer.start();
}
}
@ -220,10 +222,9 @@ void SettingsStorage::storeValue(const QString &key, const QVariant &value) @@ -220,10 +222,9 @@ void SettingsStorage::storeValue(const QString &key, const QVariant &value)
void SettingsStorage::removeValue(const QString &key)
{
const QString realKey = mapKey(key);
QWriteLocker locker(&m_lock);
if (m_data.contains(realKey)) {
const QWriteLocker locker(&m_lock);
if (m_data.remove(realKey) > 0) {
m_dirty = true;
m_data.remove(realKey);
m_timer.start();
}
}

3
src/base/settingvalue.h

@ -68,6 +68,9 @@ public: @@ -68,6 +68,9 @@ public:
CachedSettingValue<T> &operator=(const T &newValue)
{
if (m_value == newValue)
return *this;
m_value = newValue;
storeValue(m_value);
return *this;

Loading…
Cancel
Save