From 7d0caf9eec20695c402373e73fd221ff1b07b997 Mon Sep 17 00:00:00 2001 From: Christian Bouwense Date: Sun, 23 Jul 2023 14:40:46 -0400 Subject: [PATCH 1/2] refactor saveGame to use string_view instead of a const standard string reference --- apps/openmw/mwbase/statemanager.hpp | 2 +- apps/openmw/mwgui/savegamedialog.cpp | 3 ++- apps/openmw/mwstate/statemanagerimp.cpp | 2 +- apps/openmw/mwstate/statemanagerimp.hpp | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwbase/statemanager.hpp b/apps/openmw/mwbase/statemanager.hpp index 3c1d4eabfb..1a25da32b0 100644 --- a/apps/openmw/mwbase/statemanager.hpp +++ b/apps/openmw/mwbase/statemanager.hpp @@ -55,7 +55,7 @@ namespace MWBase virtual void deleteGame(const MWState::Character* character, const MWState::Slot* slot) = 0; - virtual void saveGame(const std::string& description, const MWState::Slot* slot = nullptr) = 0; + virtual void saveGame(std::string_view description, const MWState::Slot* slot = nullptr) = 0; ///< Write a saved game to \a slot or create a new slot if \a slot == 0. /// /// \note Slot must belong to the current character. diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 84b7240b2b..4b0517c3e0 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -301,7 +301,8 @@ namespace MWGui if (mSaving) { - MWBase::Environment::get().getStateManager()->saveGame(mSaveNameEdit->getCaption(), mCurrentSlot); + std::string_view nameAsStringView = std::basic_string_view(mSaveNameEdit->getCaption().asUTF8().c_str()); + MWBase::Environment::get().getStateManager()->saveGame(nameAsStringView, mCurrentSlot); } else { diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index 1e12c98582..f5db8b26ba 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -188,7 +188,7 @@ void MWState::StateManager::resumeGame() mState = State_Running; } -void MWState::StateManager::saveGame(const std::string& description, const Slot* slot) +void MWState::StateManager::saveGame(std::string_view description, const Slot* slot) { MWState::Character* character = getCurrentCharacter(); diff --git a/apps/openmw/mwstate/statemanagerimp.hpp b/apps/openmw/mwstate/statemanagerimp.hpp index f9ba51d456..df62ca7ebf 100644 --- a/apps/openmw/mwstate/statemanagerimp.hpp +++ b/apps/openmw/mwstate/statemanagerimp.hpp @@ -51,7 +51,7 @@ namespace MWState ///< Delete a saved game slot from this character. If all save slots are deleted, the character will be deleted ///< too. - void saveGame(const std::string& description, const Slot* slot = nullptr) override; + void saveGame(std::string_view description, const Slot* slot = nullptr) override; ///< Write a saved game to \a slot or create a new slot if \a slot == 0. /// /// \note Slot must belong to the current character. From 4b5d64f9e5e3530ef245bc906384708548d167d5 Mon Sep 17 00:00:00 2001 From: Christian Bouwense Date: Mon, 24 Jul 2023 14:41:17 -0400 Subject: [PATCH 2/2] inline asUTF8() instead of constructing a whole new string_view --- apps/openmw/mwgui/savegamedialog.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/savegamedialog.cpp b/apps/openmw/mwgui/savegamedialog.cpp index 4b0517c3e0..53136743d9 100644 --- a/apps/openmw/mwgui/savegamedialog.cpp +++ b/apps/openmw/mwgui/savegamedialog.cpp @@ -301,8 +301,7 @@ namespace MWGui if (mSaving) { - std::string_view nameAsStringView = std::basic_string_view(mSaveNameEdit->getCaption().asUTF8().c_str()); - MWBase::Environment::get().getStateManager()->saveGame(nameAsStringView, mCurrentSlot); + MWBase::Environment::get().getStateManager()->saveGame(mSaveNameEdit->getCaption().asUTF8(), mCurrentSlot); } else {