From cfd25f1d7cff062a3bd7f5649c2abcc2a44f2a8d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 8 Jun 2023 11:53:01 -0400 Subject: [PATCH] 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);