diff options
| author | Connor McLaughlin <stenzek@gmail.com> | 2019-08-09 23:05:48 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-09 23:05:48 +1000 |
| commit | f64f4a08c844404fe25f74d87529d4f596ab08c2 (patch) | |
| tree | 887b9fd91958092ca83750b10888e773ae1cd1dd /Source | |
| parent | ec1fe41eb28aed9f739c7e0239754e855aaeaf52 (diff) | |
| parent | 8285a94d93370a95c42cb8164928e578964ed6cd (diff) | |
Merge pull request #8290 from lioncash/const-fn
UICommon/NetPlayIndex: Minor interface cleanup
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/UICommon/NetPlayIndex.cpp | 22 | ||||
| -rw-r--r-- | Source/Core/UICommon/NetPlayIndex.h | 7 |
2 files changed, 15 insertions, 14 deletions
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<picojson::value> ParseResponse(std::vector<u8> response) +static std::optional<picojson::value> ParseResponse(const std::vector<u8>& response) { - std::string response_string(reinterpret_cast<char*>(response.data()), response.size()); + const std::string response_string(reinterpret_cast<const char*>(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<std::string, std::string>& filters) for (const auto& entry : entries.get<picojson::array>()) { - 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<std::string, std::string>& 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<std::pair<std::string, std::string>> 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<std::string> NetPlaySession::DecryptID(const std::string& password) const +std::optional<std::string> 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<void()> function) +void NetPlayIndex::SetErrorCallback(std::function<void()> 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 <map> #include <optional> #include <string> +#include <string_view> #include <thread> #include <utility> #include <vector> @@ -29,8 +30,8 @@ struct NetPlaySession bool has_password; bool in_game; - bool EncryptID(const std::string& password); - std::optional<std::string> DecryptID(const std::string& password) const; + bool EncryptID(std::string_view password); + std::optional<std::string> DecryptID(std::string_view password) const; }; class NetPlayIndex @@ -44,7 +45,7 @@ public: static std::vector<std::pair<std::string, std::string>> GetRegions(); - bool Add(NetPlaySession session); + bool Add(const NetPlaySession& session); void Remove(); bool HasActiveSession() const; |
