diff --git a/Source/Core/UICommon/NetPlayIndex.cpp b/Source/Core/UICommon/NetPlayIndex.cpp index 1606b61a76..476a43eabc 100644 --- a/Source/Core/UICommon/NetPlayIndex.cpp +++ b/Source/Core/UICommon/NetPlayIndex.cpp @@ -25,13 +25,14 @@ NetPlayIndex::~NetPlayIndex() Remove(); } -static std::optional ParseResponse(std::vector response) +static std::optional ParseResponse(const std::vector& response) { - std::string response_string(reinterpret_cast(response.data()), response.size()); + const std::string response_string(reinterpret_cast(response.data()), + response.size()); picojson::value json; - auto error = picojson::parse(json, response_string); + const auto error = picojson::parse(json, response_string); if (!error.empty()) return {}; @@ -86,8 +87,6 @@ NetPlayIndex::List(const std::map& filters) for (const auto& entry : entries.get()) { - NetPlaySession session; - const auto& name = entry.get("name"); const auto& region = entry.get("region"); const auto& method = entry.get("method"); @@ -107,6 +106,7 @@ NetPlayIndex::List(const std::map& filters) continue; } + NetPlaySession session; session.name = name.to_str(); session.region = region.to_str(); session.game_id = game_id.to_str(); @@ -160,7 +160,7 @@ void NetPlayIndex::NotificationLoop() } } -bool NetPlayIndex::Add(NetPlaySession session) +bool NetPlayIndex::Add(const NetPlaySession& session) { Common::HttpRequest request; auto response = request.Get( @@ -221,7 +221,7 @@ void NetPlayIndex::SetPlayerCount(int player_count) m_player_count = player_count; } -void NetPlayIndex::SetGame(const std::string game) +void NetPlayIndex::SetGame(std::string game) { m_game = std::move(game); } @@ -257,7 +257,7 @@ std::vector> NetPlayIndex::GetRegions() // It isn't very secure but is preferable to adding another dependency on mbedtls // The encrypted data is encoded as nibbles with the character 'A' as the base offset -bool NetPlaySession::EncryptID(const std::string& password) +bool NetPlaySession::EncryptID(std::string_view password) { if (password.empty()) return false; @@ -285,7 +285,7 @@ bool NetPlaySession::EncryptID(const std::string& password) return true; } -std::optional NetPlaySession::DecryptID(const std::string& password) const +std::optional NetPlaySession::DecryptID(std::string_view password) const { if (password.empty()) return {}; @@ -333,7 +333,7 @@ bool NetPlayIndex::HasActiveSession() const return !m_secret.empty(); } -void NetPlayIndex::SetErrorCallback(std::function function) +void NetPlayIndex::SetErrorCallback(std::function callback) { - m_error_callback = function; + m_error_callback = std::move(callback); } diff --git a/Source/Core/UICommon/NetPlayIndex.h b/Source/Core/UICommon/NetPlayIndex.h index f451301152..04f1d8b3b1 100644 --- a/Source/Core/UICommon/NetPlayIndex.h +++ b/Source/Core/UICommon/NetPlayIndex.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -29,8 +30,8 @@ struct NetPlaySession bool has_password; bool in_game; - bool EncryptID(const std::string& password); - std::optional DecryptID(const std::string& password) const; + bool EncryptID(std::string_view password); + std::optional DecryptID(std::string_view password) const; }; class NetPlayIndex @@ -44,7 +45,7 @@ public: static std::vector> GetRegions(); - bool Add(NetPlaySession session); + bool Add(const NetPlaySession& session); void Remove(); bool HasActiveSession() const;