[Lldb-commits] [lldb] d28bc54 - [lldb] Remove cache in get_demangled_name_without_arguments
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Wed May 26 09:28:09 PDT 2021
Author: Raphael Isemann
Date: 2021-05-26T18:27:40+02:00
New Revision: d28bc54ff44aad7b080177ef85764d7c5444f031
URL: https://github.com/llvm/llvm-project/commit/d28bc54ff44aad7b080177ef85764d7c5444f031
DIFF: https://github.com/llvm/llvm-project/commit/d28bc54ff44aad7b080177ef85764d7c5444f031.diff
LOG: [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
Added:
Modified:
lldb/source/Core/Mangled.cpp
Removed:
################################################################################
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 3919cb440ab40..82cabc0300113 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -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
More information about the lldb-commits
mailing list