PPCSymbolDB: Optimise symbol lookups

This commit is contained in:
Léo Lam 2017-09-07 21:43:01 +02:00
parent 8cd8e9d905
commit cc40931d64
1 changed files with 13 additions and 12 deletions

View File

@ -79,19 +79,20 @@ void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& nam
Symbol* PPCSymbolDB::GetSymbolFromAddr(u32 addr) Symbol* PPCSymbolDB::GetSymbolFromAddr(u32 addr)
{ {
XFuncMap::iterator it = functions.find(addr); XFuncMap::iterator it = functions.lower_bound(addr);
if (it != functions.end()) if (it == functions.end())
{ return nullptr;
// If the address is exactly the start address of a symbol, we're done.
if (it->second.address == addr)
return &it->second; return &it->second;
}
else // Otherwise, check whether the address is within the bounds of a symbol.
{ if (it != functions.begin())
for (auto& p : functions) --it;
{ if (addr >= it->second.address && addr < it->second.address + it->second.size)
if (addr >= p.second.address && addr < p.second.address + p.second.size) return &it->second;
return &p.second;
}
}
return nullptr; return nullptr;
} }