From c9eee9bf7f6623c2ca9429d4e3e02a8eac2bb117 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 5 Mar 2025 11:17:09 -0800 Subject: [PATCH] Config: Stop using config values with list when unnecessary With the previous fixes in place, we can now stop burning a fextl::list in every single config option. This list is only required for strarray options so reserve it for those entirely. We also don't need to save the config option enum for each, so these actually go from ~32 bytes per object down to their base type for most everything. --- FEXCore/Source/Interface/Config/Config.cpp | 5 +- FEXCore/include/FEXCore/Config/Config.h | 70 ++++++++-------------- Source/Tools/FEXLoader/ELFCodeLoader.h | 2 +- 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/FEXCore/Source/Interface/Config/Config.cpp b/FEXCore/Source/Interface/Config/Config.cpp index 75103bf12..74497a44d 100644 --- a/FEXCore/Source/Interface/Config/Config.cpp +++ b/FEXCore/Source/Interface/Config/Config.cpp @@ -482,12 +482,13 @@ template Value::Value(FEXCore::Config::ConfigOption _Option, uint8_t De template Value::Value(FEXCore::Config::ConfigOption _Option, uint64_t Default); template -void Value::GetListIfExists(FEXCore::Config::ConfigOption Option, fextl::list* List) { +void Value::GetListIfExists(FEXCore::Config::ConfigOption Option, DefaultValues::Type::StringArrayType* List) { auto Value = FEXCore::Config::All(Option); List->clear(); if (Value) { *List = **Value; } } -template void Value::GetListIfExists(FEXCore::Config::ConfigOption Option, fextl::list* List); +template void Value::GetListIfExists(FEXCore::Config::ConfigOption Option, + DefaultValues::Type::StringArrayType* List); } // namespace FEXCore::Config diff --git a/FEXCore/include/FEXCore/Config/Config.h b/FEXCore/include/FEXCore/Config/Config.h index 3134dfa2e..6ca3369a2 100644 --- a/FEXCore/include/FEXCore/Config/Config.h +++ b/FEXCore/include/FEXCore/Config/Config.h @@ -114,9 +114,10 @@ namespace DefaultValues { #include namespace Type { + using StringArrayType = fextl::list; #define OPT_BASE(type, group, enum, json, default) using P(enum) = P(type); #define OPT_STR(group, enum, json, default) using P(enum) = fextl::string; -#define OPT_STRARRAY(group, enum, json, default) OPT_STR(group, enum, json, default) +#define OPT_STRARRAY(group, enum, json, default) using P(enum) = StringArrayType; #include } // namespace Type #define FEX_CONFIG_OPT(name, enum) \ @@ -230,50 +231,17 @@ FEX_DEFAULT_VISIBILITY void EraseSet(ConfigOption Option, std::string_view Data) template class FEX_DEFAULT_VISIBILITY Value { public: + // Single value type. template - requires (!std::is_same_v) - Value(FEXCore::Config::ConfigOption _Option, TT Default) - : Option {_Option} { + requires (std::is_fundamental_v || std::is_same_v) + Value(FEXCore::Config::ConfigOption Option, TT Default) { ValueData = GetIfExists(Option, Default); } template - requires (std::is_same_v) - Value(FEXCore::Config::ConfigOption _Option, TT Default) - : Option {_Option} { + requires (std::is_fundamental_v || std::is_same_v) + Value(FEXCore::Config::ConfigOption Option, std::string_view Default) { ValueData = GetIfExists(Option, Default); - GetListIfExists(Option, &AppendList); - } - - template - requires (std::is_same_v) - Value(FEXCore::Config::ConfigOption _Option, std::string_view Default) - : Option {_Option} { - ValueData = GetIfExists(Option, Default); - GetListIfExists(Option, &AppendList); - } - - template - requires (!std::is_same_v) - Value(FEXCore::Config::ConfigOption _Option) - : Option {_Option} { - if (!FEXCore::Config::Exists(Option)) { - ERROR_AND_DIE_FMT("FEXCore::Config::Value has no value"); - } - - ValueData = Get(Option); - } - - template - requires (std::is_same_v) - Value(FEXCore::Config::ConfigOption _Option) - : Option {_Option} { - if (!FEXCore::Config::Exists(Option)) { - ERROR_AND_DIE_FMT("FEXCore::Config::Value has no value"); - } - - ValueData = GetIfExists(Option); - GetListIfExists(Option, &AppendList); } operator T() const { @@ -281,7 +249,7 @@ public: } template - requires (!std::is_same_v) + requires (std::is_fundamental_v) T operator()() const { return ValueData; } @@ -292,22 +260,32 @@ public: return ValueData; } + template + requires (!std::is_same_v) Value(T Value) { ValueData = std::move(Value); } - fextl::list& All() { - return AppendList; + + // Array value types. + template + requires (std::is_same_v) + Value(FEXCore::Config::ConfigOption Option, std::string_view) { + GetListIfExists(Option, &ValueData); + } + + template + requires (std::is_same_v) + DefaultValues::Type::StringArrayType& All() { + return ValueData; } private: - FEXCore::Config::ConfigOption Option; - T ValueData; - fextl::list AppendList; + T ValueData {}; static T Get(FEXCore::Config::ConfigOption Option); static T GetIfExists(FEXCore::Config::ConfigOption Option, T Default); static T GetIfExists(FEXCore::Config::ConfigOption Option, std::string_view Default); - static void GetListIfExists(FEXCore::Config::ConfigOption Option, fextl::list* List); + static void GetListIfExists(FEXCore::Config::ConfigOption Option, DefaultValues::Type::StringArrayType* List); }; } // namespace FEXCore::Config diff --git a/Source/Tools/FEXLoader/ELFCodeLoader.h b/Source/Tools/FEXLoader/ELFCodeLoader.h index e9c5be870..1508b0c76 100644 --- a/Source/Tools/FEXLoader/ELFCodeLoader.h +++ b/Source/Tools/FEXLoader/ELFCodeLoader.h @@ -227,7 +227,7 @@ public: ELFCodeLoader(const fextl::string& Filename, int ProgramFDFromEnv, const fextl::string& RootFS, [[maybe_unused]] const fextl::vector& args, const fextl::vector& ParsedArgs, - char** const envp = nullptr, FEXCore::Config::Value* AdditionalEnvp = nullptr) + char** const envp = nullptr, FEXCore::Config::Value* AdditionalEnvp = nullptr) : Args {args} { bool LoadedWithFD = false;