summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-06-21 18:46:27 +0200
committerPatric Stout <github@truebrain.nl>2021-06-26 20:28:34 +0200
commit98e653dacc98d308e440503c9cf9bba01933d1b4 (patch)
treee90907756d28cfc68d9200d094e790984ca0606a /src/settings.cpp
parentf35e6c1c7fdaefc9153a54c089dbaa6e2549e6b1 (diff)
downloadopenttd-98e653dacc98d308e440503c9cf9bba01933d1b4.tar.xz
Fix #9386: compilers failing to compile with LTO by using variants instead of new + unique_ptr
With std::variant all memory can be figured out at compile time, so the compiler needs to keep track of fewer elements. It also saves out a unique_ptr and its memory management, over a slight impact for resolving a setting.
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 5e3ba5be7..9d0e125b0 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -87,6 +87,7 @@ std::string _config_file; ///< Configuration file of OpenTTD
typedef std::list<ErrorMessageData> ErrorList;
static ErrorList _settings_error_list; ///< Errors while loading minimal settings.
+typedef span<const SettingVariant> SettingTable;
typedef void SettingDescProc(IniFile *ini, const SettingTable &desc, const char *grpname, void *object, bool only_startup);
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
@@ -98,9 +99,9 @@ static bool IsSignedVarMemType(VarType vt);
* @param desc The type of the iterator of the value in SettingTable.
* @return The actual pointer to SettingDesc.
*/
-static const SettingDesc *GetSettingDesc(const std::unique_ptr<const SettingDesc> &desc)
+static constexpr const SettingDesc *GetSettingDesc(const SettingVariant &desc)
{
- return desc.get();
+ return std::visit([](auto&& arg) -> const SettingDesc * { return &arg; }, desc);
}
/**