forked from OSchip/llvm-project
[lldb] Remove cache in get_demangled_name_without_arguments
This function has a single-value caching based on function local static variables. This causes two problems: * There is no synchronization, so this function randomly returns the demangled name of other functions that are demangled at the same time. * The 1-element cache is not very effective (the cache rate is around 0% when running the LLDB test suite that calls this function around 30k times). I would propose just removing it. To prevent anyone else the git archeology: the static result variables were originally added as this returned a ConstString reference, but that has since been changed so that this returns by value. Reviewed By: #lldb, JDevlieghere, shafik Differential Revision: https://reviews.llvm.org/D103107
This commit is contained in:
parent
1b47a3de48
commit
d28bc54ff4
|
@ -35,26 +35,8 @@ static inline bool cstring_is_mangled(llvm::StringRef s) {
|
|||
return Mangled::GetManglingScheme(s) != Mangled::eManglingSchemeNone;
|
||||
}
|
||||
|
||||
static ConstString
|
||||
get_demangled_name_without_arguments(ConstString mangled,
|
||||
ConstString demangled) {
|
||||
// This pair is <mangled name, demangled name without function arguments>
|
||||
static std::pair<ConstString, ConstString>
|
||||
g_most_recent_mangled_to_name_sans_args;
|
||||
|
||||
// Need to have the mangled & demangled names we're currently examining as
|
||||
// statics so we can return a const ref to them at the end of the func if we
|
||||
// don't have anything better.
|
||||
static ConstString g_last_mangled;
|
||||
static ConstString g_last_demangled;
|
||||
|
||||
if (mangled && g_most_recent_mangled_to_name_sans_args.first == mangled) {
|
||||
return g_most_recent_mangled_to_name_sans_args.second;
|
||||
}
|
||||
|
||||
g_last_demangled = demangled;
|
||||
g_last_mangled = mangled;
|
||||
|
||||
static ConstString GetDemangledNameWithoutArguments(ConstString mangled,
|
||||
ConstString demangled) {
|
||||
const char *mangled_name_cstr = mangled.GetCString();
|
||||
|
||||
if (demangled && mangled_name_cstr && mangled_name_cstr[0]) {
|
||||
|
@ -73,17 +55,13 @@ get_demangled_name_without_arguments(ConstString mangled,
|
|||
if (!cxx_method.GetContext().empty())
|
||||
shortname = cxx_method.GetContext().str() + "::";
|
||||
shortname += cxx_method.GetBasename().str();
|
||||
ConstString result(shortname.c_str());
|
||||
g_most_recent_mangled_to_name_sans_args.first = mangled;
|
||||
g_most_recent_mangled_to_name_sans_args.second = result;
|
||||
return g_most_recent_mangled_to_name_sans_args.second;
|
||||
return ConstString(shortname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (demangled)
|
||||
return g_last_demangled;
|
||||
return g_last_mangled;
|
||||
return demangled;
|
||||
return mangled;
|
||||
}
|
||||
|
||||
#pragma mark Mangled
|
||||
|
@ -347,7 +325,7 @@ ConstString Mangled::GetName(Mangled::NamePreference preference) const {
|
|||
ConstString demangled = GetDemangledName();
|
||||
|
||||
if (preference == ePreferDemangledWithoutArguments) {
|
||||
return get_demangled_name_without_arguments(m_mangled, demangled);
|
||||
return GetDemangledNameWithoutArguments(m_mangled, demangled);
|
||||
}
|
||||
if (preference == ePreferDemangled) {
|
||||
// Call the accessor to make sure we get a demangled name in case it hasn't
|
||||
|
|
Loading…
Reference in New Issue