[llvm] r318822 - [llvm-tblgen] - Stop using std::string in RecordKeeper.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 21 23:53:48 PST 2017
Author: grimar
Date: Tue Nov 21 23:53:48 2017
New Revision: 318822
URL: http://llvm.org/viewvc/llvm-project?rev=318822&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/utils/TableGen/CTagsEmitter.cpp
Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=318822&r1=318821&r2=318822&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Tue Nov 21 23:53:48 2017
@@ -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:
Modified: llvm/trunk/utils/TableGen/CTagsEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CTagsEmitter.cpp?rev=318822&r1=318821&r2=318822&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CTagsEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/CTagsEmitter.cpp Tue Nov 21 23:53:48 2017
@@ -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";
}
};
More information about the llvm-commits
mailing list