diff --git a/src/settings.cpp b/src/settings.cpp index 13855d27d9..5a1db8cf26 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1877,16 +1877,16 @@ void SyncCompanySettings() * @param force_newgame force the newgame settings * @note Strings WILL NOT be synced over the network */ -bool SetSettingValue(const StringSettingDesc *sd, std::string value, bool force_newgame) +bool SetSettingValue(const StringSettingDesc *sd, std::string_view value, bool force_newgame) { assert(sd->flags.Test(SettingFlag::NoNetworkSync)); - if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ && value.compare("(null)") == 0) { - value.clear(); + if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ && value == "(null)") { + value = {}; } const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game; - sd->AsStringSetting()->ChangeValue(object, value); + sd->AsStringSetting()->ChangeValue(object, std::string{value}); return true; } @@ -1896,7 +1896,7 @@ bool SetSettingValue(const StringSettingDesc *sd, std::string value, bool force_ * @param object The object the setting is in. * @param newval The new value for the setting. */ -void StringSettingDesc::ChangeValue(const void *object, std::string &newval) const +void StringSettingDesc::ChangeValue(const void *object, std::string &&newval) const { this->MakeValueValid(newval); if (this->pre_check != nullptr && !this->pre_check(newval)) return; diff --git a/src/settings_internal.h b/src/settings_internal.h index 4c91f95b97..8c500ac230 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -334,7 +334,7 @@ struct StringSettingDesc : SettingDesc { PostChangeCallback *post_callback; ///< Callback when the setting has been changed. bool IsStringSetting() const override { return true; } - void ChangeValue(const void *object, std::string &newval) const; + void ChangeValue(const void *object, std::string &&newval) const; std::string FormatValue(const void *object) const override; void ParseValue(const IniItem *item, void *object) const override; @@ -392,7 +392,7 @@ const SettingDesc *GetSettingFromName(const std::string_view name); void GetSaveLoadFromSettingTable(SettingTable settings, std::vector &saveloads); SettingTable GetSaveLoadSettingTable(); bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame = false); -bool SetSettingValue(const StringSettingDesc *sd, const std::string value, bool force_newgame = false); +bool SetSettingValue(const StringSettingDesc *sd, std::string_view value, bool force_newgame = false); std::vector GetFilteredSettingCollection(std::function func);