From 65c666cb57aee6e298cab4eece70c752b081f6ee Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 14 Jul 2024 19:30:35 +0100 Subject: [PATCH] Codechange: Remove unused size field from struct SaveLoad (#12859) --- src/saveload/saveload.cpp | 4 ++-- src/saveload/saveload.h | 9 ++++----- src/saveload/settings_sl.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 7f04432298..24eb4aa54d 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -1776,7 +1776,7 @@ std::vector SlTableHeader(const SaveLoadTable &slt) } /* We don't know this field, so read to nothing. */ - saveloads.push_back({key, saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, 0, nullptr, 0, handler}); + saveloads.push_back({key, saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, nullptr, 0, handler}); continue; } @@ -1883,7 +1883,7 @@ std::vector SlCompatTableHeader(const SaveLoadTable &slt, const SaveLo /* In old savegames there can be data we no longer care for. We * skip this by simply reading the amount of bytes indicated and * send those to /dev/null. */ - saveloads.push_back({"", SL_NULL, GetVarFileType(slc.null_type) | SLE_VAR_NULL, slc.null_length, slc.version_from, slc.version_to, 0, nullptr, 0, nullptr}); + saveloads.push_back({"", SL_NULL, GetVarFileType(slc.null_type) | SLE_VAR_NULL, slc.null_length, slc.version_from, slc.version_to, nullptr, 0, nullptr}); } else { auto sld_it = key_lookup.find(slc.name); /* If this branch triggers, it means that an entry in the diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index a820c7c4f1..9149d42711 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -707,7 +707,6 @@ struct SaveLoad { uint16_t length; ///< (Conditional) length of the variable (eg. arrays) (max array size is 65536 elements). SaveLoadVersion version_from; ///< Save/load the variable starting from this savegame version. SaveLoadVersion version_to; ///< Save/load the variable before this savegame version. - size_t size; ///< The sizeof size. SaveLoadAddrProc *address_proc; ///< Callback proc the get the actual variable address in memory. size_t extra_data; ///< Extra data for the callback proc. std::shared_ptr handler; ///< Custom handler for Save/Load procs. @@ -823,7 +822,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @note In general, it is better to use one of the SLE_* macros below. */ #define SLE_GENERAL_NAME(cmd, name, base, variable, type, length, from, to, extra) \ - SaveLoad {name, cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { \ + SaveLoad {name, cmd, type, length, from, to, [] (void *b, size_t) -> void * { \ static_assert(SlCheckVarSize(cmd, type, length, sizeof(static_cast(b)->variable))); \ assert(b != nullptr); \ return const_cast(static_cast(std::addressof(static_cast(b)->variable))); \ @@ -1052,7 +1051,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @note In general, it is better to use one of the SLEG_* macros below. */ #define SLEG_GENERAL(name, cmd, variable, type, length, from, to, extra) \ - SaveLoad {name, cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { \ + SaveLoad {name, cmd, type, length, from, to, [] (void *, size_t) -> void * { \ static_assert(SlCheckVarSize(cmd, type, length, sizeof(variable))); \ return static_cast(std::addressof(variable)); }, extra, nullptr} @@ -1104,7 +1103,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @param from First savegame version that has the struct. * @param to Last savegame version that has the struct. */ -#define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, 0, nullptr, 0, std::make_shared()} +#define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, nullptr, 0, std::make_shared()} /** * Storage of a global reference list in some savegame versions. @@ -1133,7 +1132,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @param from First savegame version that has the list. * @param to Last savegame version that has the list. */ -#define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, 0, nullptr, 0, std::make_shared()} +#define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, nullptr, 0, std::make_shared()} /** * Storage of a global variable in every savegame version. diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp index 987344f952..0d09ec4cd9 100644 --- a/src/saveload/settings_sl.cpp +++ b/src/saveload/settings_sl.cpp @@ -84,7 +84,7 @@ static std::vector GetSettingsDesc(const SettingTable &settings, bool if (is_loading && (sd->flags & SF_NO_NETWORK_SYNC) && _networking && !_network_server) { if (IsSavegameVersionBefore(SLV_TABLE_CHUNKS)) { /* We don't want to read this setting, so we do need to skip over it. */ - saveloads.push_back({sd->GetName(), sd->save.cmd, GetVarFileType(sd->save.conv) | SLE_VAR_NULL, sd->save.length, sd->save.version_from, sd->save.version_to, 0, nullptr, 0, nullptr}); + saveloads.push_back({sd->GetName(), sd->save.cmd, GetVarFileType(sd->save.conv) | SLE_VAR_NULL, sd->save.length, sd->save.version_from, sd->save.version_to, nullptr, 0, nullptr}); } continue; }