From fb625e0c38ab763d32819220565391af46af6fd4 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 22 Nov 2017 07:53:48 +0000 Subject: [PATCH] [llvm-tblgen] - Stop using std::string in RecordKeeper. RecordKeeper::getDef() is a hot place, it shows up in profiling and it creates std::string instance for each search in RecordMap though RecordKeeper::RecordMap can use StringRef as a key instead to avoid that. Patch do that change. Differential revision: https://reviews.llvm.org/D40170 llvm-svn: 318822 --- include/llvm/TableGen/Record.h | 2 +- utils/TableGen/CTagsEmitter.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index 55b4dfe2fa2..d0e6ddbb878 100644 --- a/include/llvm/TableGen/Record.h +++ b/include/llvm/TableGen/Record.h @@ -1525,7 +1525,7 @@ struct MultiClass { }; class RecordKeeper { - using RecordMap = std::map>; + using RecordMap = std::map>; RecordMap Classes, Defs; public: diff --git a/utils/TableGen/CTagsEmitter.cpp b/utils/TableGen/CTagsEmitter.cpp index 5213cd90446..e72430078ba 100644 --- a/utils/TableGen/CTagsEmitter.cpp +++ b/utils/TableGen/CTagsEmitter.cpp @@ -28,18 +28,17 @@ namespace { class Tag { private: - const std::string *Id; + StringRef Id; SMLoc Loc; public: - Tag(const std::string &Name, const SMLoc Location) - : Id(&Name), Loc(Location) {} - int operator<(const Tag &B) const { return *Id < *B.Id; } + Tag(StringRef Name, const SMLoc Location) : Id(Name), Loc(Location) {} + int operator<(const Tag &B) const { return Id < B.Id; } void emit(raw_ostream &OS) const { const MemoryBuffer *CurMB = SrcMgr.getMemoryBuffer(SrcMgr.FindBufferContainingLoc(Loc)); auto BufferName = CurMB->getBufferIdentifier(); std::pair LineAndColumn = SrcMgr.getLineAndColumn(Loc); - OS << *Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n"; + OS << Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n"; } };