From e015025d908f827cebb566ba7b32a672802d1819 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sat, 4 May 2019 10:42:18 +0200 Subject: [PATCH] Minor optimization to settings I/O. --- src/emucore/Settings.cxx | 8 ++++---- src/emucore/Settings.hxx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 289c4815b..6bddc4598 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -205,11 +205,11 @@ void Settings::load(const Options& options) { Options fromFile = myRespository->load(); for (const auto& opt: fromFile) - setValue(opt.first, opt.second); + setValue(opt.first, opt.second, false); // Apply commandline options, which override those from settings file for(const auto& opt: options) - setValue(opt.first, opt.second); + setValue(opt.first, opt.second, false); // Finally, validate some settings, so the rest of the codebase // can assume the values are valid @@ -593,12 +593,12 @@ const Variant& Settings::value(const string& key) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Settings::setValue(const string& key, const Variant& value) +void Settings::setValue(const string& key, const Variant& value, bool persist) { auto it = myPermanentSettings.find(key); if(it != myPermanentSettings.end()) { + if (persist && it->second != value) myRespository->save(key, value); it->second = value; - myRespository->save(key, value); } else myTemporarySettings[key] = value; diff --git a/src/emucore/Settings.hxx b/src/emucore/Settings.hxx index 1da0d49f8..7cf1bd082 100644 --- a/src/emucore/Settings.hxx +++ b/src/emucore/Settings.hxx @@ -88,7 +88,7 @@ class Settings @param key The key of the setting @param value The value to assign to the key */ - void setValue(const string& key, const Variant& value); + void setValue(const string& key, const Variant& value, bool persist = true); /** Convenience methods to return specific types.