summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Config
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-11-27 02:36:33 +0100
committerGitHub <noreply@github.com>2020-11-27 02:36:33 +0100
commit2a855348054cd328cb26ba162aa2ebbe8c6c292c (patch)
treede2808ef03333abe7af87226ed4fdf674181d534 /Source/Core/Common/Config
parentcecbc65ea0a9758b6ff754fd013797aec74045db (diff)
parent2f264c64486fdb0d6ff880cce30e229803d4105c (diff)
Merge pull request #9283 from JosJuice/config-get-speedup
Common: Optimize Config::Get
Diffstat (limited to 'Source/Core/Common/Config')
-rw-r--r--Source/Core/Common/Config/Config.cpp19
-rw-r--r--Source/Core/Common/Config/Config.h8
2 files changed, 26 insertions, 1 deletions
diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp
index 29004787e4..03c0aed72e 100644
--- a/Source/Core/Common/Config/Config.cpp
+++ b/Source/Core/Common/Config/Config.cpp
@@ -178,6 +178,25 @@ LayerType GetActiveLayerForConfig(const Location& config)
return LayerType::Base;
}
+std::optional<std::string> GetAsString(const Location& config)
+{
+ std::optional<std::string> result;
+ ReadLock lock(s_layers_rw_lock);
+
+ for (auto layer : SEARCH_ORDER)
+ {
+ const auto it = s_layers.find(layer);
+ if (it != s_layers.end())
+ {
+ result = it->second->Get<std::string>(config);
+ if (result.has_value())
+ break;
+ }
+ }
+
+ return result;
+}
+
ConfigChangeCallbackGuard::ConfigChangeCallbackGuard()
{
++s_callback_guards;
diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h
index fa315857bf..1fbaef0f88 100644
--- a/Source/Core/Common/Config/Config.h
+++ b/Source/Core/Common/Config/Config.h
@@ -39,6 +39,8 @@ std::optional<System> GetSystemFromName(const std::string& system);
const std::string& GetLayerName(LayerType layer);
LayerType GetActiveLayerForConfig(const Location&);
+std::optional<std::string> GetAsString(const Location&);
+
template <typename T>
T Get(LayerType layer, const Info<T>& info)
{
@@ -50,7 +52,11 @@ T Get(LayerType layer, const Info<T>& info)
template <typename T>
T Get(const Info<T>& info)
{
- return GetLayer(GetActiveLayerForConfig(info.location))->Get(info);
+ const std::optional<std::string> str = GetAsString(info.location);
+ if (!str)
+ return info.default_value;
+
+ return detail::TryParse<T>(*str).value_or(info.default_value);
}
template <typename T>