Dramatically improves C++ demangling performance by introducing a new implementation that is much faster than the existing demangler. While not yet complete, the new demangler will fail gracefully when it encounters symbols it isn’t prepared to deal with. In these cases LLDB will fall back to using the full demangler to prevent a loss in functionality. On sizable code bases the fast path succeeds 95% of the time, providing a significant net win.
The new implementation is located in source/Core/FastDemangle.cpp. It’s fairly straightforward C code with a few basic C++ extensions. It should compile with little or no change on a variety of platforms, but of course it is still only useful for symbols that comply with the Itanium ABI mangling spec (plus a few Clang extensions.)
<rdar://problem/15397553> <rdar://problem/15794867>
llvm-svn: 213671
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 8df9fb8..b20013f 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -20,6 +20,14 @@
#ifdef LLDB_USE_BUILTIN_DEMANGLER
+// Provide a fast-path demangler implemented in FastDemangle.cpp until it can
+// replace the existing C++ demangler with a complete implementation
+namespace lldb_private
+{
+ extern char * FastDemangle (const char * mangled_name,
+ long mangled_name_length);
+}
+
//----------------------------------------------------------------------
// Inlined copy of:
// http://llvm.org/svn/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp
@@ -5129,7 +5137,6 @@
}
}
-
//----------------------------------------------------------------------
// Generate the demangled name on demand using this accessor. Code in
// this class will need to use this accessor if it wishes to decode
@@ -5151,6 +5158,7 @@
// Don't bother running anything that isn't mangled
const char *mangled_cstr = m_mangled.GetCString();
+ long mangled_length = m_mangled.GetLength();
if (cstring_is_mangled(mangled_cstr))
{
if (!m_mangled.GetMangledCounterpart(m_demangled))
@@ -5158,7 +5166,13 @@
// We didn't already mangle this name, demangle it and if all goes well
// add it to our map.
#ifdef LLDB_USE_BUILTIN_DEMANGLER
- char *demangled_name = __cxa_demangle (mangled_cstr, NULL, NULL, NULL);
+ // Try to use the fast-path demangler first for the
+ // performance win, falling back to the full demangler only
+ // when necessary
+ char *demangled_name = FastDemangle (mangled_cstr,
+ mangled_length);
+ if (!demangled_name)
+ demangled_name = __cxa_demangle (mangled_cstr, NULL, NULL, NULL);
#elif defined(_MSC_VER)
// Cannot demangle on msvc.
char *demangled_name = nullptr;