From 04b9f6c28d54aa2f6f202763a9414cb9f6c1348a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 11 Dec 2023 07:49:40 -0500 Subject: [PATCH 1/2] Common/SettingsHandler: Use std::erase in Decrypt() Same behavior, way less verbose code. --- Source/Core/Common/SettingsHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index c36805d4ce..81e5da5989 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -81,7 +81,7 @@ void SettingsHandler::Decrypt() // (see the comment in WriteLine), lines can be separated by CRLFLF. // To handle this, we remove every CR and treat LF as the line ending. // (We ignore empty lines.) - decoded.erase(std::remove(decoded.begin(), decoded.end(), '\x0d'), decoded.end()); + std::erase(decoded, '\x0d'); } void SettingsHandler::Reset() From 88a973131cd3f865651bd4169a6e3bf6826fdecc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 11 Dec 2023 07:53:10 -0500 Subject: [PATCH 2/2] Common/SettingsHandler: Use std::string_view more We don't need to enforce the use of std::string instances with AddSetting(). We can accept views and only construct one string, rather than three temporaries. --- Source/Core/Common/SettingsHandler.cpp | 6 +++--- Source/Core/Common/SettingsHandler.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp index 81e5da5989..dd84b6967b 100644 --- a/Source/Core/Common/SettingsHandler.cpp +++ b/Source/Core/Common/SettingsHandler.cpp @@ -92,12 +92,12 @@ void SettingsHandler::Reset() m_buffer = {}; } -void SettingsHandler::AddSetting(const std::string& key, const std::string& value) +void SettingsHandler::AddSetting(std::string_view key, std::string_view value) { - WriteLine(key + '=' + value + "\r\n"); + WriteLine(fmt::format("{}={}\r\n", key, value)); } -void SettingsHandler::WriteLine(const std::string& str) +void SettingsHandler::WriteLine(std::string_view str) { const u32 old_position = m_position; const u32 old_key = m_key; diff --git a/Source/Core/Common/SettingsHandler.h b/Source/Core/Common/SettingsHandler.h index b0765c753e..c550e8e7f4 100644 --- a/Source/Core/Common/SettingsHandler.h +++ b/Source/Core/Common/SettingsHandler.h @@ -27,7 +27,7 @@ public: SettingsHandler(); explicit SettingsHandler(Buffer&& buffer); - void AddSetting(const std::string& key, const std::string& value); + void AddSetting(std::string_view key, std::string_view value); const Buffer& GetBytes() const; void SetBytes(Buffer&& buffer); @@ -38,7 +38,7 @@ public: static std::string GenerateSerialNumber(); private: - void WriteLine(const std::string& str); + void WriteLine(std::string_view str); void WriteByte(u8 b); std::array m_buffer;