mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
Add caching to Config::Info
The goal of this change is to make Config::Get(const Info<T>&) fast so that we can use it in hot paths.
This commit is contained in:
@ -24,7 +24,10 @@ std::shared_ptr<Layer> GetLayer(LayerType layer);
|
||||
void RemoveLayer(LayerType layer);
|
||||
|
||||
void AddConfigChangedCallback(ConfigChangedCallback func);
|
||||
void InvokeConfigChangedCallbacks();
|
||||
void OnConfigChanged();
|
||||
|
||||
// Returns the number of times the config has changed in the current execution of the program
|
||||
u64 GetConfigVersion();
|
||||
|
||||
// Explicit load and save of layers
|
||||
void Load();
|
||||
@ -51,6 +54,23 @@ T Get(LayerType layer, const Info<T>& info)
|
||||
|
||||
template <typename T>
|
||||
T Get(const Info<T>& info)
|
||||
{
|
||||
CachedValue<T> cached = info.GetCachedValue();
|
||||
const u64 config_version = GetConfigVersion();
|
||||
|
||||
if (cached.config_version < config_version)
|
||||
{
|
||||
cached.value = GetUncached(info);
|
||||
cached.config_version = config_version;
|
||||
|
||||
info.SetCachedValue(cached);
|
||||
}
|
||||
|
||||
return cached.value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T GetUncached(const Info<T>& info)
|
||||
{
|
||||
const std::optional<std::string> str = GetAsString(info.GetLocation());
|
||||
if (!str)
|
||||
@ -75,7 +95,7 @@ template <typename T>
|
||||
void Set(LayerType layer, const Info<T>& info, const std::common_type_t<T>& value)
|
||||
{
|
||||
GetLayer(layer)->Set(info, value);
|
||||
InvokeConfigChangedCallbacks();
|
||||
OnConfigChanged();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -99,7 +119,7 @@ void SetBaseOrCurrent(const Info<T>& info, const std::common_type_t<T>& value)
|
||||
Set<T>(LayerType::CurrentRun, info, value);
|
||||
}
|
||||
|
||||
// Used to defer InvokeConfigChangedCallbacks until after the completion of many config changes.
|
||||
// Used to defer OnConfigChanged until after the completion of many config changes.
|
||||
class ConfigChangeCallbackGuard
|
||||
{
|
||||
public:
|
||||
|
Reference in New Issue
Block a user