From 867e7d259d46e4798784e152358f49982b78ab1f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 11:45:12 -0400 Subject: [PATCH 1/5] BreakpointDialog: Pass QString by const reference to invalid_input Gets rid of redundant copying. --- Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp b/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp index 78611f7d45..990ad7b9e0 100644 --- a/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp +++ b/Source/Core/DolphinQt/Debugger/BreakpointDialog.cpp @@ -251,7 +251,7 @@ void BreakpointDialog::OnAddressTypeChanged() void BreakpointDialog::accept() { - auto invalid_input = [this](QString field) { + auto invalid_input = [this](const QString& field) { ModalMessageBox::critical(this, tr("Error"), tr("Invalid input for the field \"%1\"").arg(field)); }; From c99b0f2eb86e3437e6913c3bc87307b2ccc5f5fb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 11:46:14 -0400 Subject: [PATCH 2/5] BreakpointWidget: Pass QString by const reference to create_item Avoids churning string copies when performing updates. --- Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp index 588c353d88..de04411ece 100644 --- a/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp @@ -168,7 +168,7 @@ void BreakpointWidget::Update() int i = 0; m_table->setRowCount(i); - const auto create_item = [](const QString string = {}) { + const auto create_item = [](const QString& string = {}) { QTableWidgetItem* item = new QTableWidgetItem(string); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); return item; From 496aea54c0a25812c56175dfcaaee48ad9fe117b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 11:48:06 -0400 Subject: [PATCH 3/5] CodeDiffDialog: Pass QString by const reference to create_item Avoids churning string copies when updating --- Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp b/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp index b043fbecba..bdb00edd01 100644 --- a/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp @@ -361,7 +361,7 @@ void CodeDiffDialog::Update(bool include) OnExclude(); } - const auto create_item = [](const QString string = {}, const u32 address = 0x00000000) { + const auto create_item = [](const QString& string = {}, const u32 address = 0x00000000) { QTableWidgetItem* item = new QTableWidgetItem(string); item->setData(Qt::UserRole, address); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); From cfd25f1d7cff062a3bd7f5649c2abcc2a44f2a8d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 11:53:01 -0400 Subject: [PATCH 4/5] CodeDiffDialog: Construct Diff instance in CalculateSymbolsFromProfile() when necessary We can move the construction of the Diff instance into the body of the if statement, so that we only construct this if the condition is true. While we're at it, we can move the symbol description string into the instance, getting rid of a copy. The function itself can also be const qualified. --- .../DolphinQt/Debugger/CodeDiffDialog.cpp | 22 +++++++++---------- .../Core/DolphinQt/Debugger/CodeDiffDialog.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp b/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp index bdb00edd01..d495a868c8 100644 --- a/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp @@ -279,7 +279,7 @@ void CodeDiffDialog::OnExclude() } } -std::vector CodeDiffDialog::CalculateSymbolsFromProfile() +std::vector CodeDiffDialog::CalculateSymbolsFromProfile() const { Profiler::ProfileStats prof_stats; auto& blockstats = prof_stats.block_stats; @@ -288,23 +288,23 @@ std::vector CodeDiffDialog::CalculateSymbolsFromProfile() current.reserve(20000); // Convert blockstats to smaller struct Diff. Exclude repeat functions via symbols. - for (auto& iter : blockstats) + for (const auto& iter : blockstats) { - Diff tmp_diff; std::string symbol = g_symbolDB.GetDescription(iter.addr); if (!std::any_of(current.begin(), current.end(), - [&symbol](Diff& v) { return v.symbol == symbol; })) + [&symbol](const Diff& v) { return v.symbol == symbol; })) { - tmp_diff.symbol = symbol; - tmp_diff.addr = iter.addr; - tmp_diff.hits = iter.run_count; - tmp_diff.total_hits = iter.run_count; - current.push_back(tmp_diff); + current.push_back(Diff{ + .addr = iter.addr, + .symbol = std::move(symbol), + .hits = static_cast(iter.run_count), + .total_hits = static_cast(iter.run_count), + }); } } - sort(current.begin(), current.end(), - [](const Diff& v1, const Diff& v2) { return (v1.symbol < v2.symbol); }); + std::sort(current.begin(), current.end(), + [](const Diff& v1, const Diff& v2) { return (v1.symbol < v2.symbol); }); return current; } diff --git a/Source/Core/DolphinQt/Debugger/CodeDiffDialog.h b/Source/Core/DolphinQt/Debugger/CodeDiffDialog.h index ac156dea91..3278359afe 100644 --- a/Source/Core/DolphinQt/Debugger/CodeDiffDialog.h +++ b/Source/Core/DolphinQt/Debugger/CodeDiffDialog.h @@ -38,7 +38,7 @@ private: void ClearBlockCache(); void OnClickItem(); void OnRecord(bool enabled); - std::vector CalculateSymbolsFromProfile(); + std::vector CalculateSymbolsFromProfile() const; void OnInclude(); void OnExclude(); void RemoveMissingSymbolsFromIncludes(const std::vector& symbol_diff); From 2b0a9477d04579877d0225b94a3bcd618dea5918 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 12:01:56 -0400 Subject: [PATCH 5/5] MemoryViewWidget: Use QStringView with ConvertTextToBytes Allows for avoiding string copies. While we're at it, we can also mark ConvertTextToBytes as const. --- Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp | 2 +- Source/Core/DolphinQt/Debugger/MemoryViewWidget.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp index 519dea6ebe..752c4680a0 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp @@ -609,7 +609,7 @@ AddressSpace::Type MemoryViewWidget::GetAddressSpace() const return m_address_space; } -std::vector MemoryViewWidget::ConvertTextToBytes(Type type, QString input_text) +std::vector MemoryViewWidget::ConvertTextToBytes(Type type, QStringView input_text) const { if (type == Type::Null) return {}; diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h index 1b8bed117a..c958ede341 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h @@ -60,7 +60,7 @@ public: void UpdateFont(); void ToggleBreakpoint(u32 addr, bool row); - std::vector ConvertTextToBytes(Type type, QString input_text); + std::vector ConvertTextToBytes(Type type, QStringView input_text) const; void SetAddressSpace(AddressSpace::Type address_space); AddressSpace::Type GetAddressSpace() const; void SetDisplay(Type type, int bytes_per_row, int alignment, bool dual_view);