diff --git a/llvm/tools/llvm-xray/func-id-helper.cc b/llvm/tools/llvm-xray/func-id-helper.cc index 3234010695b2..9bf55b23bdd1 100644 --- a/llvm/tools/llvm-xray/func-id-helper.cc +++ b/llvm/tools/llvm-xray/func-id-helper.cc @@ -19,6 +19,10 @@ using namespace llvm; using namespace xray; std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const { + auto CacheIt = CachedNames.find(FuncId); + if (CacheIt != CachedNames.end()) + return CacheIt->second; + std::ostringstream F; auto It = FunctionAddresses.find(FuncId); if (It == FunctionAddresses.end()) { @@ -37,7 +41,9 @@ std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const { F << "@(" << std::hex << It->second << ")"; }); - return F.str(); + auto S = F.str(); + CachedNames[FuncId] = S; + return S; } std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const { diff --git a/llvm/tools/llvm-xray/func-id-helper.h b/llvm/tools/llvm-xray/func-id-helper.h index 7348a7100b05..3e0780d54f90 100644 --- a/llvm/tools/llvm-xray/func-id-helper.h +++ b/llvm/tools/llvm-xray/func-id-helper.h @@ -13,6 +13,7 @@ #ifndef LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H #define LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H +#include "llvm/ADT/DenseMap.h" #include "llvm/DebugInfo/Symbolize/Symbolize.h" #include @@ -28,6 +29,7 @@ private: std::string BinaryInstrMap; symbolize::LLVMSymbolizer &Symbolizer; const FunctionAddressMap &FunctionAddresses; + mutable llvm::DenseMap CachedNames; public: FuncIdConversionHelper(std::string BinaryInstrMap,