Introduce a simple "hint" scheme to eliminate the quadratic behavior
associated with deserializing macro history for an identifier.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165729 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 736f082..5657ee2 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -1241,7 +1241,8 @@
}
}
-void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) {
+void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset,
+ MacroInfo *Hint) {
llvm::BitstreamCursor &Stream = F.MacroCursor;
// Keep track of where we are in the stream, then jump back there
@@ -1370,7 +1371,7 @@
MI->setHidden(Hidden);
// Finally, install the macro.
- PP.addLoadedMacroInfo(II, MI);
+ PP.addLoadedMacroInfo(II, MI, Hint);
// Remember that we saw this macro last so that we add the tokens that
// form its body to it.
@@ -5795,7 +5796,7 @@
return LocalID + I->second;
}
-MacroInfo *ASTReader::getMacro(MacroID ID) {
+MacroInfo *ASTReader::getMacro(MacroID ID, MacroInfo *Hint) {
if (ID == 0)
return 0;
@@ -5811,7 +5812,7 @@
assert(I != GlobalMacroMap.end() && "Corrupted global macro map");
ModuleFile *M = I->second;
unsigned Index = ID - M->BaseMacroID;
- ReadMacroRecord(*M, M->MacroOffsets[Index]);
+ ReadMacroRecord(*M, M->MacroOffsets[Index], Hint);
}
return MacrosLoaded[ID];
@@ -6512,9 +6513,10 @@
for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) {
// FIXME: std::move here
SmallVector<MacroID, 2> GlobalIDs = PendingMacroIDs.begin()[I].second;
+ MacroInfo *Hint = 0;
for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs;
++IDIdx) {
- getMacro(GlobalIDs[IDIdx]);
+ Hint = getMacro(GlobalIDs[IDIdx], Hint);
}
}
PendingMacroIDs.clear();