diff options
| author | Greg Clayton <gclayton@apple.com> | 2010-09-03 23:26:12 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2010-09-03 23:26:12 +0000 |
| commit | e41e58997c36b4f2d1071d79d84fb10419cce3bb (patch) | |
| tree | 3fa506514483e46ebc5857977b3da3ff79251a5c /lldb/source/Core/Mangled.cpp | |
| parent | 207b9d62185776485f5788a584b026816afcd037 (diff) | |
| download | bcm5719-llvm-e41e58997c36b4f2d1071d79d84fb10419cce3bb.tar.gz bcm5719-llvm-e41e58997c36b4f2d1071d79d84fb10419cce3bb.zip | |
Improved name demangling performance by 20% on darwin.
llvm-svn: 113032
Diffstat (limited to 'lldb/source/Core/Mangled.cpp')
| -rw-r--r-- | lldb/source/Core/Mangled.cpp | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp index 5b48c5a2c0c..c3657952c16 100644 --- a/lldb/source/Core/Mangled.cpp +++ b/lldb/source/Core/Mangled.cpp @@ -9,6 +9,8 @@ #include <cxxabi.h> +#include "llvm/ADT/DenseMap.h" + #include "lldb/Core/ConstString.h" #include "lldb/Core/Mangled.h" #include "lldb/Core/Stream.h" @@ -142,18 +144,47 @@ Mangled::GetDemangledName () const const char * mangled = m_mangled.AsCString(); if (mangled[0]) { - char *demangled_name = abi::__cxa_demangle (mangled, NULL, NULL, NULL); - - if (demangled_name) + // Since demangling can be a costly, and since all names that go + // into a ConstString (like our m_mangled and m_demangled members) + // end up being unique "const char *" values, we can use a DenseMap + // to speed up our lookup. We do this because often our symbol table + // and our debug information both have the mangled names which they + // would each need to demangle. Also, with GCC we end up with the one + // definition rule where a lot of STL code produces symbols that are + // in multiple compile units and the mangled names end up being in + // the same binary multiple times. The performance win isn't huge, + // but we showed a 20% improvement on darwin. + typedef llvm::DenseMap<const char *, const char *> MangledToDemangledMap; + static MangledToDemangledMap g_mangled_to_demangled; + + // Check our mangled string pointer to demangled string pointer map first + MangledToDemangledMap::const_iterator pos = g_mangled_to_demangled.find (mangled); + if (pos != g_mangled_to_demangled.end()) { - m_demangled.SetCString (demangled_name); - free (demangled_name); + // We have already demangled this string, we can just use our saved result! + m_demangled.SetCString(pos->second); } else { - // Set the demangled string to the empty string to indicate we - // tried to parse it once and failed. - m_demangled.SetCString(""); + // We didn't already mangle this name, demangle it and if all goes well + // add it to our map. + char *demangled_name = abi::__cxa_demangle (mangled, NULL, NULL, NULL); + + if (demangled_name) + { + m_demangled.SetCString (demangled_name); + // Now that the name has been uniqued, add the uniqued C string + // pointer from m_mangled as the key to the uniqued C string + // pointer in m_demangled. + g_mangled_to_demangled.insert (std::make_pair (mangled, m_demangled.GetCString())); + free (demangled_name); + } + else + { + // Set the demangled string to the empty string to indicate we + // tried to parse it once and failed. + m_demangled.SetCString(""); + } } } } |

