[llvm-tblgen] - Stop using std::string in RecordKeeper.
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 22 Nov 2017 07:53:48 +0000 (07:53 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 22 Nov 2017 07:53:48 +0000 (07:53 +0000)
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

llvm/include/llvm/TableGen/Record.h
llvm/utils/TableGen/CTagsEmitter.cpp

index 55b4dfe..d0e6ddb 100644 (file)
@@ -1525,7 +1525,7 @@ struct MultiClass {
 };
 
 class RecordKeeper {
-  using RecordMap = std::map<std::string, std::unique_ptr<Record>>;
+  using RecordMap = std::map<StringRef, std::unique_ptr<Record>>;
   RecordMap Classes, Defs;
 
 public:
index 5213cd9..e724300 100644 (file)
@@ -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<unsigned, unsigned> LineAndColumn = SrcMgr.getLineAndColumn(Loc);
-    OS << *Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n";
+    OS << Id << "\t" << BufferName << "\t" << LineAndColumn.first << "\n";
   }
 };