Optimize searching for existing symbols.

Checking every time is slow, we should just skip by the address.  Some is
just the locking overhead.
This commit is contained in:
Unknown W. Brackets 2014-02-14 22:26:35 -08:00
parent 7c2d36e802
commit 8948990871
3 changed files with 17 additions and 1 deletions

View file

@ -566,6 +566,15 @@ u32 SymbolMap::GetFunctionStart(u32 address) const {
return INVALID_ADDRESS;
}
u32 SymbolMap::FindPossibleFunctionAtAfter(u32 address) const {
lock_guard guard(lock_);
auto it = activeFunctions.lower_bound(address);
if (it == activeFunctions.end()) {
return (u32)-1;
}
return it->first;
}
u32 SymbolMap::GetFunctionSize(u32 startAddress) const {
lock_guard guard(lock_);
auto it = activeFunctions.find(startAddress);

View file

@ -95,6 +95,9 @@ public:
u32 GetFunctionSize(u32 startAddress) const;
bool SetFunctionSize(u32 startAddress, u32 newSize);
bool RemoveFunction(u32 startAddress, bool removeName);
// Search for the first address their may be a function after address.
// Only valid for currently loaded modules. Not guaranteed there will be a function.
u32 FindPossibleFunctionAtAfter(u32 address) const;
void AddLabel(const char* name, u32 address, int moduleIndex = -1);
std::string GetLabelString(u32 address) const;

View file

@ -385,10 +385,14 @@ skip:
bool isStraightLeaf = true;
u32 addr;
u32 addrNextSym = 0;
for (addr = startAddr; addr <= endAddr; addr += 4) {
// Use pre-existing symbol map info if available. May be more reliable.
SymbolInfo syminfo;
if (symbolMap.GetSymbolInfo(&syminfo, addr, ST_FUNCTION)) {
if (addrNextSym <= addr) {
addrNextSym = symbolMap.FindPossibleFunctionAtAfter(addr);
}
if (addrNextSym <= addr && symbolMap.GetSymbolInfo(&syminfo, addr, ST_FUNCTION)) {
addr = syminfo.address + syminfo.size - 4;
// We still need to insert the func for hashing purposes.