Merge pull request #12557 from mitaclaw/cpu-thread-guarantees-1

CheatSearch: Remove redundant lambdas
This commit is contained in:
Admiral H. Curtiss 2024-02-03 02:45:06 +01:00 committed by GitHub
commit 4e3886e7e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 87 deletions

View File

@ -211,37 +211,28 @@ Cheats::NewSearch(const Core::CPUThreadGuard& guard,
if (Config::Get(Config::RA_HARDCORE_ENABLED))
return Cheats::SearchErrorCode::DisabledInHardcoreMode;
#endif // USE_RETRO_ACHIEVEMENTS
const u32 data_size = sizeof(T);
std::vector<Cheats::SearchResult<T>> results;
Cheats::SearchErrorCode error_code = Cheats::SearchErrorCode::Success;
Core::RunAsCPUThread([&] {
const Core::State core_state = Core::GetState();
if (core_state != Core::State::Running && core_state != Core::State::Paused)
{
error_code = Cheats::SearchErrorCode::NoEmulationActive;
return;
}
return Cheats::SearchErrorCode::NoEmulationActive;
const auto& ppc_state = guard.GetSystem().GetPPCState();
if (address_space == PowerPC::RequestedAddressSpace::Virtual && !ppc_state.msr.DR)
{
error_code = Cheats::SearchErrorCode::VirtualAddressesCurrentlyNotAccessible;
return;
}
return Cheats::SearchErrorCode::VirtualAddressesCurrentlyNotAccessible;
for (const Cheats::MemoryRange& range : memory_ranges)
{
if (range.m_length < data_size)
if (range.m_length < sizeof(T))
continue;
const u32 increment_per_loop = aligned ? data_size : 1;
const u32 start_address = aligned ? Common::AlignUp(range.m_start, data_size) : range.m_start;
const u32 increment_per_loop = aligned ? sizeof(T) : 1;
const u32 start_address = aligned ? Common::AlignUp(range.m_start, sizeof(T)) : range.m_start;
const u64 aligned_length = range.m_length - (start_address - range.m_start);
if (aligned_length < data_size)
if (aligned_length < sizeof(T))
continue;
const u64 length = aligned_length - (data_size - 1);
const u64 length = aligned_length - (sizeof(T) - 1);
for (u64 i = 0; i < length; i += increment_per_loop)
{
const u32 addr = start_address + i;
@ -260,10 +251,7 @@ Cheats::NewSearch(const Core::CPUThreadGuard& guard,
}
}
}
});
if (error_code == Cheats::SearchErrorCode::Success)
return results;
return error_code;
}
template <typename T>
@ -278,21 +266,13 @@ Cheats::NextSearch(const Core::CPUThreadGuard& guard,
return Cheats::SearchErrorCode::DisabledInHardcoreMode;
#endif // USE_RETRO_ACHIEVEMENTS
std::vector<Cheats::SearchResult<T>> results;
Cheats::SearchErrorCode error_code = Cheats::SearchErrorCode::Success;
Core::RunAsCPUThread([&] {
const Core::State core_state = Core::GetState();
if (core_state != Core::State::Running && core_state != Core::State::Paused)
{
error_code = Cheats::SearchErrorCode::NoEmulationActive;
return;
}
return Cheats::SearchErrorCode::NoEmulationActive;
const auto& ppc_state = guard.GetSystem().GetPPCState();
if (address_space == PowerPC::RequestedAddressSpace::Virtual && !ppc_state.msr.DR)
{
error_code = Cheats::SearchErrorCode::VirtualAddressesCurrentlyNotAccessible;
return;
}
return Cheats::SearchErrorCode::VirtualAddressesCurrentlyNotAccessible;
for (const auto& previous_result : previous_results)
{
@ -308,8 +288,7 @@ Cheats::NextSearch(const Core::CPUThreadGuard& guard,
// if the previous state was invalid we always update the value to avoid getting stuck in an
// invalid state
if (!previous_result.IsValueValid() ||
validator(current_value->value, previous_result.m_value))
if (!previous_result.IsValueValid() || validator(current_value->value, previous_result.m_value))
{
auto& r = results.emplace_back();
r.m_value = current_value->value;
@ -319,10 +298,7 @@ Cheats::NextSearch(const Core::CPUThreadGuard& guard,
r.m_address = addr;
}
}
});
if (error_code == Cheats::SearchErrorCode::Success)
return results;
return error_code;
}
Cheats::CheatSearchSessionBase::~CheatSearchSessionBase() = default;

View File

@ -301,9 +301,7 @@ void CheatSearchWidget::OnNextScanClicked()
}
}
const Cheats::SearchErrorCode error_code = [this, &guard] {
return m_session->RunSearch(guard);
}();
const Cheats::SearchErrorCode error_code = m_session->RunSearch(guard);
if (error_code == Cheats::SearchErrorCode::Success)
{