mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 13:28:50 +03:00
Avoid double lookups
This commit is contained in:
parent
d2c21ce507
commit
daf52a2610
2 changed files with 11 additions and 7 deletions
|
@ -202,17 +202,19 @@ bool SettingsStorage::save()
|
||||||
|
|
||||||
QVariant SettingsStorage::loadValue(const QString &key, const QVariant &defaultValue) const
|
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);
|
return m_data.value(mapKey(key), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsStorage::storeValue(const QString &key, const QVariant &value)
|
void SettingsStorage::storeValue(const QString &key, const QVariant &value)
|
||||||
{
|
{
|
||||||
const QString realKey = mapKey(key);
|
const QString realKey = mapKey(key);
|
||||||
QWriteLocker locker(&m_lock);
|
const QWriteLocker locker(&m_lock);
|
||||||
if (m_data.value(realKey) != value) {
|
|
||||||
|
QVariant ¤tValue = m_data[realKey];
|
||||||
|
if (currentValue != value) {
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
m_data.insert(realKey, value);
|
currentValue = value;
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,10 +222,9 @@ void SettingsStorage::storeValue(const QString &key, const QVariant &value)
|
||||||
void SettingsStorage::removeValue(const QString &key)
|
void SettingsStorage::removeValue(const QString &key)
|
||||||
{
|
{
|
||||||
const QString realKey = mapKey(key);
|
const QString realKey = mapKey(key);
|
||||||
QWriteLocker locker(&m_lock);
|
const QWriteLocker locker(&m_lock);
|
||||||
if (m_data.contains(realKey)) {
|
if (m_data.remove(realKey) > 0) {
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
m_data.remove(realKey);
|
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,9 @@ public:
|
||||||
|
|
||||||
CachedSettingValue<T> &operator=(const T &newValue)
|
CachedSettingValue<T> &operator=(const T &newValue)
|
||||||
{
|
{
|
||||||
|
if (m_value == newValue)
|
||||||
|
return *this;
|
||||||
|
|
||||||
m_value = newValue;
|
m_value = newValue;
|
||||||
storeValue(m_value);
|
storeValue(m_value);
|
||||||
return *this;
|
return *this;
|
||||||
|
|
Loading…
Reference in a new issue