From cc40931d6422506a36cb6838372dae1e8b5f3de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 7 Sep 2017 21:43:01 +0200 Subject: [PATCH] PPCSymbolDB: Optimise symbol lookups --- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index b4aaa6145a..f9ce0508a3 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -79,19 +79,20 @@ void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& nam Symbol* PPCSymbolDB::GetSymbolFromAddr(u32 addr) { - XFuncMap::iterator it = functions.find(addr); - if (it != functions.end()) - { + XFuncMap::iterator it = functions.lower_bound(addr); + 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; - } - else - { - for (auto& p : functions) - { - if (addr >= p.second.address && addr < p.second.address + p.second.size) - return &p.second; - } - } + + // Otherwise, check whether the address is within the bounds of a symbol. + if (it != functions.begin()) + --it; + if (addr >= it->second.address && addr < it->second.address + it->second.size) + return &it->second; + return nullptr; }