diff options
| author | JosJuice <josjuice@gmail.com> | 2020-11-25 16:26:13 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2020-11-25 16:26:13 +0100 |
| commit | 2f264c64486fdb0d6ff880cce30e229803d4105c (patch) | |
| tree | 1256d85674cd291faf7dd5c6b267a5f3465d6dac /Source/Core/Common/Config/Config.cpp | |
| parent | 140daf59606e3fc4f3544ef152eec9738b29bab5 (diff) | |
Common: Optimize Config::Get
The way Config::Get works in master, it first calls
Config::GetActiveLayerForConfig which searches for the
setting in all layers, and then calls Config::Layer::Get
which searches for the same setting again within the given
layer. We can remove this second search by combining the
logic of Config::GetActiveLayerForConfig and
Config::Layer::Get into one function.
Diffstat (limited to 'Source/Core/Common/Config/Config.cpp')
| -rw-r--r-- | Source/Core/Common/Config/Config.cpp | 19 |
1 files changed, 19 insertions, 0 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; |
