diff --git a/src/settings.cpp b/src/settings.cpp index 6e0c38bd64..fae2eb64f5 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -3210,30 +3210,24 @@ static void SaveSettings(const SettingTable &settings, void *object) * N bytes setting field */ -/** Sorted list of PATX settings, generated by MakeSettingsPatxList */ -static std::vector _sorted_patx_settings; - /** * Prepare a sorted list of settings to be potentially be loaded out of the PATX chunk * This is to enable efficient lookup of settings by name - * This is stored in _sorted_patx_settings */ -static void MakeSettingsPatxList(const SettingTable &settings) +static std::vector MakeSettingsPatxList(const SettingTable &settings) { - static const SettingTable *previous = nullptr; + std::vector sorted_patx_settings; - if (&settings == previous) return; - previous = &settings; - - _sorted_patx_settings.clear(); for (auto &sd : settings) { if (sd->patx_name == nullptr) continue; - _sorted_patx_settings.push_back(sd.get()); + sorted_patx_settings.push_back(sd.get()); } - std::sort(_sorted_patx_settings.begin(), _sorted_patx_settings.end(), [](const SettingDesc *a, const SettingDesc *b) { + std::sort(sorted_patx_settings.begin(), sorted_patx_settings.end(), [](const SettingDesc *a, const SettingDesc *b) { return strcmp(a->patx_name, b->patx_name) < 0; }); + + return sorted_patx_settings; } /** @@ -3274,7 +3268,7 @@ static const SaveLoad _settings_ext_save_desc[] = { */ static void LoadSettingsPatx(const SettingTable &settings, void *object) { - MakeSettingsPatxList(settings); + std::vector sorted_patx_settings = MakeSettingsPatxList(settings); SettingsExtLoad current_setting; @@ -3291,14 +3285,14 @@ static void LoadSettingsPatx(const SettingTable &settings, void *object) // now try to find corresponding setting bool exact_match = false; - auto iter = std::lower_bound(_sorted_patx_settings.begin(), _sorted_patx_settings.end(), current_setting.name, [&](const SettingDesc *a, const char *b) { + auto iter = std::lower_bound(sorted_patx_settings.begin(), sorted_patx_settings.end(), current_setting.name, [&](const SettingDesc *a, const char *b) { int result = strcmp(a->patx_name, b); if (result == 0) exact_match = true; return result < 0; }); if (exact_match) { - assert(iter != _sorted_patx_settings.end()); + assert(iter != sorted_patx_settings.end()); // found setting const SettingDesc *setting = (*iter); const SaveLoad &sld = setting->save;