From 08223bad9f46f6c23bac915ae8d41eb7eac71b64 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 06:09:47 -0400 Subject: [PATCH 1/7] VideoCommon/NetPlayChatUI: Set member variable within the constructor initializer list Member variables should be initialized within the constructor initializer list if possible. --- Source/Core/VideoCommon/NetPlayChatUI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/NetPlayChatUI.cpp b/Source/Core/VideoCommon/NetPlayChatUI.cpp index 7587229ee0..29becc020f 100644 --- a/Source/Core/VideoCommon/NetPlayChatUI.cpp +++ b/Source/Core/VideoCommon/NetPlayChatUI.cpp @@ -14,8 +14,8 @@ constexpr size_t MAX_BACKLOG_SIZE = 100; std::unique_ptr g_netplay_chat_ui; NetPlayChatUI::NetPlayChatUI(std::function callback) + : m_message_callback{std::move(callback)} { - m_message_callback = std::move(callback); } void NetPlayChatUI::Display() From 50a15b7484af90441f556bb0febd87b41818c5b6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 06:12:27 -0400 Subject: [PATCH 2/7] VideoCommon/NetPlayChatUI: Take std::string by value in AppendChat() Given we're simply storing the std::string into a deque. We can emplace it and move it. Completely avoiding copies with the current usage of the function. --- Source/Core/VideoCommon/NetPlayChatUI.cpp | 4 ++-- Source/Core/VideoCommon/NetPlayChatUI.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/NetPlayChatUI.cpp b/Source/Core/VideoCommon/NetPlayChatUI.cpp index 29becc020f..6c8bce9227 100644 --- a/Source/Core/VideoCommon/NetPlayChatUI.cpp +++ b/Source/Core/VideoCommon/NetPlayChatUI.cpp @@ -78,12 +78,12 @@ void NetPlayChatUI::Display() ImGui::End(); } -void NetPlayChatUI::AppendChat(const std::string& message, NetPlayChatUI::Color color) +void NetPlayChatUI::AppendChat(std::string message, Color color) { if (m_messages.size() > MAX_BACKLOG_SIZE) m_messages.pop_front(); - m_messages.push_back({message, color}); + m_messages.emplace_back(std::move(message), color); // Only scroll to bottom, if we were at the bottom previously if (m_is_scrolled_to_bottom) diff --git a/Source/Core/VideoCommon/NetPlayChatUI.h b/Source/Core/VideoCommon/NetPlayChatUI.h index baef71329b..8ec13a770d 100644 --- a/Source/Core/VideoCommon/NetPlayChatUI.h +++ b/Source/Core/VideoCommon/NetPlayChatUI.h @@ -20,7 +20,7 @@ public: using Color = std::array; void Display(); - void AppendChat(const std::string& message, Color color); + void AppendChat(std::string message, Color color); void SendMessage(); void Activate(); From 53b115b81e626d563afb62939ac192f56974817b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 06:14:40 -0400 Subject: [PATCH 3/7] VideoCommon/NetPlayChatUI: Use nullptr where applicable We gotsa type dedicated to this concept already :P --- Source/Core/VideoCommon/NetPlayChatUI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/NetPlayChatUI.cpp b/Source/Core/VideoCommon/NetPlayChatUI.cpp index 6c8bce9227..7428233286 100644 --- a/Source/Core/VideoCommon/NetPlayChatUI.cpp +++ b/Source/Core/VideoCommon/NetPlayChatUI.cpp @@ -106,7 +106,7 @@ void NetPlayChatUI::SendMessage() void NetPlayChatUI::Activate() { if (ImGui::IsItemFocused()) - ImGui::SetWindowFocus(NULL); + ImGui::SetWindowFocus(nullptr); else m_activate = true; } From c958fc1278f90b8fb4e401abc9a7a16f76f42401 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 06:18:55 -0400 Subject: [PATCH 4/7] VideoCommon/NetPlayChatUI: Default destructor in the cpp file Ensures that the destruction logic is kept local to the translation unit (making it nicer when it comes to forward declaring non-trivial types). It also doesn't really do much to define it in the header. --- Source/Core/VideoCommon/NetPlayChatUI.cpp | 2 ++ Source/Core/VideoCommon/NetPlayChatUI.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/NetPlayChatUI.cpp b/Source/Core/VideoCommon/NetPlayChatUI.cpp index 7428233286..a84c26d8d7 100644 --- a/Source/Core/VideoCommon/NetPlayChatUI.cpp +++ b/Source/Core/VideoCommon/NetPlayChatUI.cpp @@ -18,6 +18,8 @@ NetPlayChatUI::NetPlayChatUI(std::function callback) { } +NetPlayChatUI::~NetPlayChatUI() = default; + void NetPlayChatUI::Display() { const float scale = ImGui::GetIO().DisplayFramebufferScale.x; diff --git a/Source/Core/VideoCommon/NetPlayChatUI.h b/Source/Core/VideoCommon/NetPlayChatUI.h index 8ec13a770d..c995db5c50 100644 --- a/Source/Core/VideoCommon/NetPlayChatUI.h +++ b/Source/Core/VideoCommon/NetPlayChatUI.h @@ -15,7 +15,7 @@ class NetPlayChatUI { public: explicit NetPlayChatUI(std::function callback); - ~NetPlayChatUI() = default; + ~NetPlayChatUI(); using Color = std::array; From 0fabab07606883fdd2b31b263d54a2a2908aed16 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 06:16:28 -0400 Subject: [PATCH 5/7] VideoCommon/NetPlayGolfUI: Initialize netplay_client in the constructor initializer list --- Source/Core/VideoCommon/NetPlayGolfUI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/NetPlayGolfUI.cpp b/Source/Core/VideoCommon/NetPlayGolfUI.cpp index 3a831b1cf1..42fd1186db 100644 --- a/Source/Core/VideoCommon/NetPlayGolfUI.cpp +++ b/Source/Core/VideoCommon/NetPlayGolfUI.cpp @@ -16,8 +16,8 @@ constexpr float DEFAULT_WINDOW_HEIGHT = 45.0f; std::unique_ptr g_netplay_golf_ui; NetPlayGolfUI::NetPlayGolfUI(std::shared_ptr netplay_client) + : m_netplay_client{netplay_client} { - m_netplay_client = netplay_client; } void NetPlayGolfUI::Display() From cf0f2bbf1d6703d2c568e36636b4a467f6787214 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 06:17:24 -0400 Subject: [PATCH 6/7] VideoCommon/NetPlayGolfUI: Default the destructor in the cpp file Ensures the destruction logic is kept local to the translation unit. It also doesn't really do much to have it specified in the header. --- Source/Core/VideoCommon/NetPlayGolfUI.cpp | 2 ++ Source/Core/VideoCommon/NetPlayGolfUI.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/NetPlayGolfUI.cpp b/Source/Core/VideoCommon/NetPlayGolfUI.cpp index 42fd1186db..fe67f9a63f 100644 --- a/Source/Core/VideoCommon/NetPlayGolfUI.cpp +++ b/Source/Core/VideoCommon/NetPlayGolfUI.cpp @@ -20,6 +20,8 @@ NetPlayGolfUI::NetPlayGolfUI(std::shared_ptr netplay_cli { } +NetPlayGolfUI::~NetPlayGolfUI() = default; + void NetPlayGolfUI::Display() { auto client = m_netplay_client.lock(); diff --git a/Source/Core/VideoCommon/NetPlayGolfUI.h b/Source/Core/VideoCommon/NetPlayGolfUI.h index 097c6cf600..0f7abdb384 100644 --- a/Source/Core/VideoCommon/NetPlayGolfUI.h +++ b/Source/Core/VideoCommon/NetPlayGolfUI.h @@ -16,7 +16,7 @@ class NetPlayGolfUI { public: explicit NetPlayGolfUI(std::shared_ptr netplay_client); - ~NetPlayGolfUI() = default; + ~NetPlayGolfUI(); void Display(); From 778623c48c9236e3fde42c7a643fc6d7bd05ee55 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 06:20:55 -0400 Subject: [PATCH 7/7] VideoCommon/NetPlayGolfUI: Remove unused header This header doesn't actually make use of any std::string facilities. --- Source/Core/VideoCommon/NetPlayGolfUI.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/VideoCommon/NetPlayGolfUI.h b/Source/Core/VideoCommon/NetPlayGolfUI.h index 0f7abdb384..461d7fab2f 100644 --- a/Source/Core/VideoCommon/NetPlayGolfUI.h +++ b/Source/Core/VideoCommon/NetPlayGolfUI.h @@ -5,7 +5,6 @@ #pragma once #include -#include namespace NetPlay {