Skip to content

Commit

Permalink
small code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kupsch committed Oct 20, 2020
1 parent 8cd8e8c commit 1befaad
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions common/src/symbolDemangleWithCache.C
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,26 @@ static thread_local std::string lastDemangled;



// Returns a demangled symbol using symbol_demangle, but includes a per thread,
// Returns a demangled symbol using symbol_demangle with a per thread,
// single-entry cache of the previous demangling.
//
std::string const& symbol_demangle_with_cache(const std::string &symName, bool includeParams)
{
if (includeParams == lastIncludeParams && symName == lastSymName) {
// found hit, return a copy of cached demangling
return lastDemangled;
}

char *demangled = symbol_demangle(symName.c_str(), includeParams);
if (includeParams != lastIncludeParams || symName != lastSymName) {
// cache miss
char *demangled = symbol_demangle(symName.c_str(), includeParams);

if (!demangled) {
throw std::bad_alloc(); // malloc failed
}
if (!demangled) {
throw std::bad_alloc(); // malloc failed
}

// update cache
lastSymName = symName;
lastIncludeParams = includeParams;
lastDemangled = demangled;
// update cache
lastSymName = symName;
lastIncludeParams = includeParams;
lastDemangled = demangled;

free(demangled);
free(demangled);
}

return lastDemangled;
}

0 comments on commit 1befaad

Please sign in to comment.