Write MRU data to disk whenever a change is made rather than only on program exit

Originally committed to SVN as r5667.
This commit is contained in:
Thomas Goyne 2011-09-28 19:52:46 +00:00
parent 5411a57b3c
commit 6a49b5392d

View file

@ -47,7 +47,6 @@ MRUManager::MRUManager(const std::string &config, const std::string &default_con
MRUManager::~MRUManager() { MRUManager::~MRUManager() {
Flush();
} }
MRUManager::MRUListMap &MRUManager::Find(std::string const& key) { MRUManager::MRUListMap &MRUManager::Find(std::string const& key) {
@ -63,11 +62,15 @@ void MRUManager::Add(const std::string &key, const std::string &entry) {
map.remove(entry); map.remove(entry);
map.push_front(entry); map.push_front(entry);
Prune(map); Prune(map);
Flush();
} }
void MRUManager::Remove(const std::string &key, const std::string &entry) { void MRUManager::Remove(const std::string &key, const std::string &entry) {
Find(key).remove(entry); Find(key).remove(entry);
Flush();
} }
@ -106,7 +109,7 @@ void MRUManager::Flush() {
/// @brief Prune MRUListMap to the desired length. /// @brief Prune MRUListMap to the desired length.
/// This uses the user-set values for MRU list length. /// This uses the user-set values for MRU list length.
inline void MRUManager::Prune(MRUListMap& map) { inline void MRUManager::Prune(MRUListMap& map) {
map.resize(std::min(16u, map.size())); map.resize(std::min<size_t>(16, map.size()));
} }
static json::String cast_str(json::UnknownElement const& e) { static json::String cast_str(json::UnknownElement const& e) {