BreakPoints: Use std algorithms where applicable

This commit is contained in:
Lioncash 2018-03-19 02:36:38 -04:00
parent 0c128f3abe
commit 3137d4f75f
1 changed files with 48 additions and 53 deletions

View File

@ -88,16 +88,15 @@ void BreakPoints::Add(u32 address, bool temp)
void BreakPoints::Remove(u32 address) void BreakPoints::Remove(u32 address)
{ {
for (auto i = m_breakpoints.begin(); i != m_breakpoints.end(); ++i) const auto iter = std::find_if(m_breakpoints.begin(), m_breakpoints.end(),
{ [address](const auto& bp) { return bp.address == address; });
if (i->address == address)
{ if (iter == m_breakpoints.cend())
m_breakpoints.erase(i); return;
m_breakpoints.erase(iter);
if (g_jit) if (g_jit)
g_jit->GetBlockCache()->InvalidateICache(address, 4, true); g_jit->GetBlockCache()->InvalidateICache(address, 4, true);
return;
}
}
} }
void BreakPoints::Clear() void BreakPoints::Clear()
@ -187,52 +186,49 @@ void MemChecks::Add(const TMemCheck& memory_check)
void MemChecks::Remove(u32 address) void MemChecks::Remove(u32 address)
{ {
for (auto i = m_mem_checks.begin(); i != m_mem_checks.end(); ++i) const auto iter =
{ std::find_if(m_mem_checks.cbegin(), m_mem_checks.cend(),
if (i->start_address == address) [address](const auto& check) { return check.start_address == address; });
{
if (iter == m_mem_checks.cend())
return;
Core::RunAsCPUThread([&] { Core::RunAsCPUThread([&] {
m_mem_checks.erase(i); m_mem_checks.erase(iter);
if (!HasAny() && g_jit) if (!HasAny() && g_jit)
g_jit->ClearCache(); g_jit->ClearCache();
PowerPC::DBATUpdated(); PowerPC::DBATUpdated();
}); });
return;
}
}
} }
TMemCheck* MemChecks::GetMemCheck(u32 address, size_t size) TMemCheck* MemChecks::GetMemCheck(u32 address, size_t size)
{ {
for (TMemCheck& mc : m_mem_checks) const auto iter =
{ std::find_if(m_mem_checks.begin(), m_mem_checks.end(), [address, size](const auto& mc) {
if (mc.end_address >= address && address + size - 1 >= mc.start_address) return mc.end_address >= address && address + size - 1 >= mc.start_address;
{ });
return &mc;
}
}
// none found // None found
if (iter == m_mem_checks.cend())
return nullptr; return nullptr;
return &*iter;
} }
bool MemChecks::OverlapsMemcheck(u32 address, u32 length) bool MemChecks::OverlapsMemcheck(u32 address, u32 length)
{ {
if (!HasAny()) if (!HasAny())
return false; return false;
u32 page_end_suffix = length - 1;
u32 page_end_address = address | page_end_suffix; const u32 page_end_suffix = length - 1;
for (TMemCheck memcheck : m_mem_checks) const u32 page_end_address = address | page_end_suffix;
{
if (((memcheck.start_address | page_end_suffix) == page_end_address || return std::any_of(m_mem_checks.cbegin(), m_mem_checks.cend(), [&](const auto& mc) {
(memcheck.end_address | page_end_suffix) == page_end_address) || return ((mc.start_address | page_end_suffix) == page_end_address ||
((memcheck.start_address | page_end_suffix) < page_end_address && (mc.end_address | page_end_suffix) == page_end_address) ||
(memcheck.end_address | page_end_suffix) > page_end_address)) ((mc.start_address | page_end_suffix) < page_end_address &&
{ (mc.end_address | page_end_suffix) > page_end_address);
return true; });
}
}
return false;
} }
bool TMemCheck::Action(DebugInterface* debug_interface, u32 value, u32 addr, bool write, bool TMemCheck::Action(DebugInterface* debug_interface, u32 value, u32 addr, bool write,
@ -318,14 +314,13 @@ void Watches::UpdateName(int count, const std::string name)
void Watches::Remove(u32 address) void Watches::Remove(u32 address)
{ {
for (auto i = m_watches.begin(); i != m_watches.end(); ++i) const auto iter = std::find_if(m_watches.cbegin(), m_watches.cend(),
{ [address](const auto& watch) { return watch.address == address; });
if (i->address == address)
{ if (iter == m_watches.cend())
m_watches.erase(i);
return; return;
}
} m_watches.erase(iter);
} }
void Watches::Clear() void Watches::Clear()