From fa7c969e154cf8c6d89c831bbe4ad88cb54c9ffb Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 26 Oct 2023 13:06:16 -0700 Subject: [PATCH] CheatSearch: Use index range for ClonePartial Specify the begin and end indices instead of filling a vector with all the indices which are continuous anyway. --- Source/Core/Core/CheatSearch.cpp | 12 +++++------- Source/Core/Core/CheatSearch.h | 12 ++++++------ Source/Core/DolphinQt/CheatSearchWidget.cpp | 21 ++++----------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/Source/Core/Core/CheatSearch.cpp b/Source/Core/Core/CheatSearch.cpp index bf60485416..78f206ecfb 100644 --- a/Source/Core/Core/CheatSearch.cpp +++ b/Source/Core/Core/CheatSearch.cpp @@ -614,17 +614,15 @@ std::unique_ptr Cheats::CheatSearchSession::C template std::unique_ptr -Cheats::CheatSearchSession::ClonePartial(const std::vector& result_indices) const +Cheats::CheatSearchSession::ClonePartial(const size_t begin_index, const size_t end_index) const { - const auto& results = m_search_results; - std::vector> partial_results; - partial_results.reserve(result_indices.size()); - for (size_t idx : result_indices) - partial_results.push_back(results[idx]); + if (begin_index == 0 && end_index >= m_search_results.size()) + return Clone(); auto c = std::make_unique>(m_memory_ranges, m_address_space, m_aligned); - c->m_search_results = std::move(partial_results); + c->m_search_results.assign(m_search_results.begin() + begin_index, + m_search_results.begin() + end_index); c->m_compare_type = this->m_compare_type; c->m_filter_type = this->m_filter_type; c->m_value = this->m_value; diff --git a/Source/Core/Core/CheatSearch.h b/Source/Core/Core/CheatSearch.h index 696347fcf3..5f72a0a9a0 100644 --- a/Source/Core/Core/CheatSearch.h +++ b/Source/Core/Core/CheatSearch.h @@ -165,11 +165,11 @@ public: // Create a complete copy of this search session. virtual std::unique_ptr Clone() const = 0; - // Create a partial copy of this search session. Only the results with the passed indices are - // copied. This is useful if you want to run a next search on only partial result data of a + // Create a partial copy of this search session. Only the results with indices in the given range + // are copied. This is useful if you want to run a next search on only partial result data of a // previous search. - virtual std::unique_ptr - ClonePartial(const std::vector& result_indices) const = 0; + virtual std::unique_ptr ClonePartial(size_t begin_index, + size_t end_index) const = 0; }; template @@ -210,8 +210,8 @@ public: bool WasFirstSearchDone() const override; std::unique_ptr Clone() const override; - std::unique_ptr - ClonePartial(const std::vector& result_indices) const override; + std::unique_ptr ClonePartial(size_t begin_index, + size_t end_index) const override; private: std::vector> m_search_results; diff --git a/Source/Core/DolphinQt/CheatSearchWidget.cpp b/Source/Core/DolphinQt/CheatSearchWidget.cpp index 1f9d226601..4e91f5ddcd 100644 --- a/Source/Core/DolphinQt/CheatSearchWidget.cpp +++ b/Source/Core/DolphinQt/CheatSearchWidget.cpp @@ -373,28 +373,15 @@ void CheatSearchWidget::OnNextScanClicked() bool CheatSearchWidget::RefreshValues() { - const size_t result_count = m_session->GetResultCount(); - if (result_count == 0) + const size_t displayed_result_count = std::min(TABLE_MAX_ROWS, m_session->GetResultCount()); + if (displayed_result_count == 0) { m_info_label_1->setText(tr("Cannot refresh without results.")); return false; } - const bool too_many_results = result_count > TABLE_MAX_ROWS; - std::unique_ptr tmp; - if (too_many_results) - { - std::vector value_indices; - value_indices.reserve(TABLE_MAX_ROWS); - for (size_t i = 0; i < TABLE_MAX_ROWS; ++i) - value_indices.push_back(i); - tmp = m_session->ClonePartial(value_indices); - } - else - { - tmp = m_session->Clone(); - } - + std::unique_ptr tmp = + m_session->ClonePartial(0, displayed_result_count); tmp->SetFilterType(Cheats::FilterType::DoNotFilter); const Cheats::SearchErrorCode error_code = [&tmp] {