mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 21:30:19 -06:00
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.
This commit is contained in:
@ -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>
|
||||
|
Reference in New Issue
Block a user