summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Config
diff options
context:
space:
mode:
authorSilent <zdanio95@gmail.com>2019-07-30 18:43:54 +0200
committerSilent <zdanio95@gmail.com>2019-08-01 22:22:05 +0200
commit48a4b621255c1aeaeaebd3add616fa6c8738f201 (patch)
tree09b5d21dfa7c1c25c2287163c412e142a5c0ca39 /Source/Core/Common/Config
parentcb4eecde529f54ec8c62f9b2137888716c09ba27 (diff)
Change Layer code not to create superfluous std::optional entries in LayerMap
Diffstat (limited to 'Source/Core/Common/Config')
-rw-r--r--Source/Core/Common/Config/Layer.cpp10
-rw-r--r--Source/Core/Common/Config/Layer.h18
2 files changed, 17 insertions, 11 deletions
diff --git a/Source/Core/Common/Config/Layer.cpp b/Source/Core/Common/Config/Layer.cpp
index 0e201001be..573c79c04e 100644
--- a/Source/Core/Common/Config/Layer.cpp
+++ b/Source/Core/Common/Config/Layer.cpp
@@ -46,8 +46,14 @@ bool Layer::Exists(const ConfigLocation& location) const
bool Layer::DeleteKey(const ConfigLocation& location)
{
m_is_dirty = true;
- bool had_value = m_map[location].has_value();
- m_map[location].reset();
+ bool had_value = false;
+ const auto iter = m_map.find(location);
+ if (iter != m_map.end() && iter->second.has_value())
+ {
+ iter->second.reset();
+ had_value = true;
+ }
+
return had_value;
}
diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h
index dec08ab2f6..87c6b91f90 100644
--- a/Source/Core/Common/Config/Layer.h
+++ b/Source/Core/Common/Config/Layer.h
@@ -103,18 +103,18 @@ public:
void DeleteAllKeys();
template <typename T>
- T Get(const ConfigInfo<T>& config_info)
+ T Get(const ConfigInfo<T>& config_info) const
{
return Get<T>(config_info.location).value_or(config_info.default_value);
}
template <typename T>
- std::optional<T> Get(const ConfigLocation& location)
+ std::optional<T> Get(const ConfigLocation& location) const
{
- const std::optional<std::string>& str_value = m_map[location];
- if (!str_value)
+ const auto iter = m_map.find(location);
+ if (iter == m_map.end() || !iter->second.has_value())
return std::nullopt;
- return detail::TryParse<T>(*str_value);
+ return detail::TryParse<T>(*iter->second);
}
template <typename T>
@@ -129,13 +129,13 @@ public:
Set(location, ValueToString(value));
}
- void Set(const ConfigLocation& location, const std::string& new_value)
+ void Set(const ConfigLocation& location, std::string new_value)
{
- std::optional<std::string>& current_value = m_map[location];
- if (current_value == new_value)
+ const auto iter = m_map.find(location);
+ if (iter != m_map.end() && iter->second == new_value)
return;
m_is_dirty = true;
- current_value = new_value;
+ m_map.insert_or_assign(location, std::move(new_value));
}
Section GetSection(System system, const std::string& section);