Merge pull request #9311 from JosJuice/config-get-fast-2

Add caching to Config::Info
This commit is contained in:
Léo Lam authored and GitHub committed 2020-12-13 03:55:39 +01:00
commit 3634508e46
17 files changed
+188 -83

No files matched your search

+3 -3
View File
@@ -472,11 +472,11 @@ static void RestoreSYSCONF()
for (const auto& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[&](auto& info) {
[&](auto* info) {
// If this setting was overridden, then we copy the base layer value back to the SYSCONF.
// Otherwise we leave the new value in the SYSCONF.
if (Config::GetActiveLayerForConfig(info) == Config::LayerType::Base)
Config::SetBase(info, temp_layer.Get(info));
if (Config::GetActiveLayerForConfig(*info) == Config::LayerType::Base)
Config::SetBase(*info, temp_layer.Get(*info));
},
setting.config_info);
}
+11 -11
View File
@@ -24,15 +24,15 @@ const Info<u32> SYSCONF_SPEAKER_VOLUME{{System::SYSCONF, "BT", "SPKV"}, 0x58};
const Info<bool> SYSCONF_WIIMOTE_MOTOR{{System::SYSCONF, "BT", "MOT"}, true};
const std::array<SYSCONFSetting, 11> SYSCONF_SETTINGS{
{{SYSCONF_SCREENSAVER, SysConf::Entry::Type::Byte},
{SYSCONF_LANGUAGE, SysConf::Entry::Type::Byte},
{SYSCONF_COUNTRY, SysConf::Entry::Type::BigArray},
{SYSCONF_WIDESCREEN, SysConf::Entry::Type::Byte},
{SYSCONF_PROGRESSIVE_SCAN, SysConf::Entry::Type::Byte},
{SYSCONF_PAL60, SysConf::Entry::Type::Byte},
{SYSCONF_SOUND_MODE, SysConf::Entry::Type::Byte},
{SYSCONF_SENSOR_BAR_POSITION, SysConf::Entry::Type::Byte},
{SYSCONF_SENSOR_BAR_SENSITIVITY, SysConf::Entry::Type::Long},
{SYSCONF_SPEAKER_VOLUME, SysConf::Entry::Type::Byte},
{SYSCONF_WIIMOTE_MOTOR, SysConf::Entry::Type::Byte}}};
{{&SYSCONF_SCREENSAVER, SysConf::Entry::Type::Byte},
{&SYSCONF_LANGUAGE, SysConf::Entry::Type::Byte},
{&SYSCONF_COUNTRY, SysConf::Entry::Type::BigArray},
{&SYSCONF_WIDESCREEN, SysConf::Entry::Type::Byte},
{&SYSCONF_PROGRESSIVE_SCAN, SysConf::Entry::Type::Byte},
{&SYSCONF_PAL60, SysConf::Entry::Type::Byte},
{&SYSCONF_SOUND_MODE, SysConf::Entry::Type::Byte},
{&SYSCONF_SENSOR_BAR_POSITION, SysConf::Entry::Type::Byte},
{&SYSCONF_SENSOR_BAR_SENSITIVITY, SysConf::Entry::Type::Long},
{&SYSCONF_SPEAKER_VOLUME, SysConf::Entry::Type::Byte},
{&SYSCONF_WIIMOTE_MOTOR, SysConf::Entry::Type::Byte}}};
} // namespace Config
+1 -1
View File
@@ -33,7 +33,7 @@ extern const Info<bool> SYSCONF_WIIMOTE_MOTOR;
struct SYSCONFSetting
{
std::variant<Info<u32>, Info<bool>> config_info;
std::variant<const Info<u32>*, const Info<bool>*> config_info;
SysConf::Entry::Type type;
};
@@ -40,16 +40,16 @@ void SaveToSYSCONF(Config::LayerType layer)
for (const Config::SYSCONFSetting& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[layer, &setting, &sysconf](auto& info) {
const std::string key = info.location.section + "." + info.location.key;
[layer, &setting, &sysconf](auto* info) {
const std::string key = info->GetLocation().section + "." + info->GetLocation().key;
if (setting.type == SysConf::Entry::Type::Long)
{
sysconf.SetData<u32>(key, setting.type, Config::Get(layer, info));
sysconf.SetData<u32>(key, setting.type, Config::Get(layer, *info));
}
else if (setting.type == SysConf::Entry::Type::Byte)
{
sysconf.SetData<u8>(key, setting.type, static_cast<u8>(Config::Get(layer, info)));
sysconf.SetData<u8>(key, setting.type, static_cast<u8>(Config::Get(layer, *info)));
}
else if (setting.type == SysConf::Entry::Type::BigArray)
{
@@ -58,7 +58,7 @@ void SaveToSYSCONF(Config::LayerType layer)
SysConf::Entry* entry = sysconf.GetOrAddEntry(key, setting.type);
if (entry->bytes.size() < 0x1007 + 1)
entry->bytes.resize(0x1007 + 1);
*reinterpret_cast<u32*>(entry->bytes.data()) = Config::Get(layer, info);
*reinterpret_cast<u32*>(entry->bytes.data()) = Config::Get(layer, *info);
}
},
setting.config_info);
@@ -179,28 +179,29 @@ private:
for (const Config::SYSCONFSetting& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[&](auto& info) {
const std::string key = info.location.section + "." + info.location.key;
[&](auto* info) {
const Config::Location location = info->GetLocation();
const std::string key = location.section + "." + location.key;
if (setting.type == SysConf::Entry::Type::Long)
{
layer->Set(info.location, sysconf.GetData<u32>(key, info.default_value));
layer->Set(location, sysconf.GetData<u32>(key, info->GetDefaultValue()));
}
else if (setting.type == SysConf::Entry::Type::Byte)
{
layer->Set(info.location, sysconf.GetData<u8>(key, info.default_value));
layer->Set(location, sysconf.GetData<u8>(key, info->GetDefaultValue()));
}
else if (setting.type == SysConf::Entry::Type::BigArray)
{
// Somewhat hacky support for IPL.SADR. The setting only stores the
// first 4 bytes even thought the SYSCONF entry is much bigger.
u32 value = info.default_value;
u32 value = info->GetDefaultValue();
SysConf::Entry* entry = sysconf.GetEntry(key);
if (entry)
{
std::memcpy(&value, entry->bytes.data(),
std::min(entry->bytes.size(), sizeof(u32)));
}
layer->Set(info.location, value);
layer->Set(location, value);
}
},
setting.config_info);
@@ -69,10 +69,10 @@ using INIToSectionMap = std::map<std::string, std::pair<Config::System, std::str
static const INIToLocationMap& GetINIToLocationMap()
{
static const INIToLocationMap ini_to_location = {
{{"Core", "ProgressiveScan"}, {Config::SYSCONF_PROGRESSIVE_SCAN.location}},
{{"Core", "PAL60"}, {Config::SYSCONF_PAL60.location}},
{{"Wii", "Widescreen"}, {Config::SYSCONF_WIDESCREEN.location}},
{{"Wii", "Language"}, {Config::SYSCONF_LANGUAGE.location}},
{{"Core", "ProgressiveScan"}, {Config::SYSCONF_PROGRESSIVE_SCAN.GetLocation()}},
{{"Core", "PAL60"}, {Config::SYSCONF_PAL60.GetLocation()}},
{{"Wii", "Widescreen"}, {Config::SYSCONF_WIDESCREEN.GetLocation()}},
{{"Wii", "Language"}, {Config::SYSCONF_LANGUAGE.GetLocation()}},
};
return ini_to_location;
}
@@ -36,32 +36,32 @@ bool IsSettingSaveable(const Config::Location& config_location)
static constexpr std::array<const Config::Location*, 17> s_setting_saveable = {
// Main.Core
&Config::MAIN_DEFAULT_ISO.location,
&Config::MAIN_MEMCARD_A_PATH.location,
&Config::MAIN_MEMCARD_B_PATH.location,
&Config::MAIN_AUTO_DISC_CHANGE.location,
&Config::MAIN_ALLOW_SD_WRITES.location,
&Config::MAIN_DPL2_DECODER.location,
&Config::MAIN_DPL2_QUALITY.location,
&Config::MAIN_RAM_OVERRIDE_ENABLE.location,
&Config::MAIN_MEM1_SIZE.location,
&Config::MAIN_MEM2_SIZE.location,
&Config::MAIN_GFX_BACKEND.location,
&Config::MAIN_ENABLE_SAVESTATES.location,
&Config::MAIN_FALLBACK_REGION.location,
&Config::MAIN_DEFAULT_ISO.GetLocation(),
&Config::MAIN_MEMCARD_A_PATH.GetLocation(),
&Config::MAIN_MEMCARD_B_PATH.GetLocation(),
&Config::MAIN_AUTO_DISC_CHANGE.GetLocation(),
&Config::MAIN_ALLOW_SD_WRITES.GetLocation(),
&Config::MAIN_DPL2_DECODER.GetLocation(),
&Config::MAIN_DPL2_QUALITY.GetLocation(),
&Config::MAIN_RAM_OVERRIDE_ENABLE.GetLocation(),
&Config::MAIN_MEM1_SIZE.GetLocation(),
&Config::MAIN_MEM2_SIZE.GetLocation(),
&Config::MAIN_GFX_BACKEND.GetLocation(),
&Config::MAIN_ENABLE_SAVESTATES.GetLocation(),
&Config::MAIN_FALLBACK_REGION.GetLocation(),
// Main.Interface
&Config::MAIN_USE_PANIC_HANDLERS.location,
&Config::MAIN_OSD_MESSAGES.location,
&Config::MAIN_USE_PANIC_HANDLERS.GetLocation(),
&Config::MAIN_OSD_MESSAGES.GetLocation(),
// Main.Interface
&Config::MAIN_SKIP_NKIT_WARNING.location,
&Config::MAIN_SKIP_NKIT_WARNING.GetLocation(),
// UI.General
&Config::MAIN_USE_DISCORD_PRESENCE.location,
&Config::MAIN_USE_DISCORD_PRESENCE.GetLocation(),
};
return std::any_of(s_setting_saveable.cbegin(), s_setting_saveable.cend(),