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.
This commit is contained in:
Dentomologist 2023-10-26 13:06:16 -07:00
parent 03f8ec09eb
commit fa7c969e15
3 changed files with 15 additions and 30 deletions

View File

@ -614,17 +614,15 @@ std::unique_ptr<Cheats::CheatSearchSessionBase> Cheats::CheatSearchSession<T>::C
template <typename T>
std::unique_ptr<Cheats::CheatSearchSessionBase>
Cheats::CheatSearchSession<T>::ClonePartial(const std::vector<size_t>& result_indices) const
Cheats::CheatSearchSession<T>::ClonePartial(const size_t begin_index, const size_t end_index) const
{
const auto& results = m_search_results;
std::vector<SearchResult<T>> 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<Cheats::CheatSearchSession<T>>(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;

View File

@ -165,11 +165,11 @@ public:
// Create a complete copy of this search session.
virtual std::unique_ptr<CheatSearchSessionBase> 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<CheatSearchSessionBase>
ClonePartial(const std::vector<size_t>& result_indices) const = 0;
virtual std::unique_ptr<CheatSearchSessionBase> ClonePartial(size_t begin_index,
size_t end_index) const = 0;
};
template <typename T>
@ -210,8 +210,8 @@ public:
bool WasFirstSearchDone() const override;
std::unique_ptr<CheatSearchSessionBase> Clone() const override;
std::unique_ptr<CheatSearchSessionBase>
ClonePartial(const std::vector<size_t>& result_indices) const override;
std::unique_ptr<CheatSearchSessionBase> ClonePartial(size_t begin_index,
size_t end_index) const override;
private:
std::vector<SearchResult<T>> m_search_results;

View File

@ -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<Cheats::CheatSearchSessionBase> tmp;
if (too_many_results)
{
std::vector<size_t> 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<Cheats::CheatSearchSessionBase> tmp =
m_session->ClonePartial(0, displayed_result_count);
tmp->SetFilterType(Cheats::FilterType::DoNotFilter);
const Cheats::SearchErrorCode error_code = [&tmp] {