[PATCH] D34984: Store token literal data in PCH. Avoids disk read on PreProc expansion.
Vassil Vassilev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 23 01:26:02 PDT 2017
v.g.vassilev updated this revision to Diff 112303.
v.g.vassilev added a comment.
Fix StringRef allocation.
https://reviews.llvm.org/D34984
Files:
include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp
Index: lib/Serialization/ASTWriter.cpp
===================================================================
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -4364,6 +4364,8 @@
Record.push_back(Tok.getKind());
// FIXME: Should translate token flags to a stable encoding.
Record.push_back(Tok.getFlags());
+ if (Tok.isLiteral())
+ AddString(StringRef(Tok.getLiteralData(), Tok.getLength()), Record);
}
void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) {
Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -1508,6 +1508,12 @@
Tok.setIdentifierInfo(II);
Tok.setKind((tok::TokenKind)Record[Idx++]);
Tok.setFlag((Token::TokenFlags)Record[Idx++]);
+ if (Tok.isLiteral()) {
+ const RecordData &RD = reinterpret_cast<const RecordData &>(Record);
+ std::string *Lit = new std::string(ReadString(RD, Idx));
+ TokenLiteralDataLoaded.push_back(Lit);
+ Tok.setLiteralData(Lit->c_str());
+ }
return Tok;
}
@@ -10372,6 +10378,9 @@
ASTReader::~ASTReader() {
if (OwnsDeserializationListener)
delete DeserializationListener;
+ for (auto PStr : TokenLiteralDataLoaded) {
+ delete PStr;
+ }
}
IdentifierResolver &ASTReader::getIdResolver() {
Index: include/clang/Serialization/ASTReader.h
===================================================================
--- include/clang/Serialization/ASTReader.h
+++ include/clang/Serialization/ASTReader.h
@@ -612,6 +612,9 @@
/// files.
llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
+ /// \brief Token literal data loaded and owned by us.
+ std::vector<std::string *> TokenLiteralDataLoaded;
+
typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
GlobalMacroMapType;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34984.112303.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170823/2c97617f/attachment.bin>
More information about the cfe-commits
mailing list