[cfe-commits] r135554 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReader.cpp
Douglas Gregor
dgregor at apple.com
Tue Jul 19 18:10:58 PDT 2011
Author: dgregor
Date: Tue Jul 19 20:10:58 2011
New Revision: 135554
URL: http://llvm.org/viewvc/llvm-project?rev=135554&view=rev
Log:
Use a ContinuousRangeMap to map from the global selector ID in the AST
reader down to the AST file + local ID, rather than walking the PCH
chain. No functionality change; this is generalization and cleanup.
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=135554&r1=135553&r2=135554&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Jul 19 20:10:58 2011
@@ -570,6 +570,15 @@
/// been loaded.
llvm::SmallVector<Selector, 16> SelectorsLoaded;
+ typedef ContinuousRangeMap<serialization::SelectorID,
+ std::pair<PerFileData *, int32_t>, 4>
+ GlobalSelectorMapType;
+
+ /// \brief Mapping from global selector IDs to the module in which the
+ /// selector resides along with the offset that should be added to the
+ /// global selector ID to produce a local ID.
+ GlobalSelectorMapType GlobalSelectorMap;
+
/// \brief The macro definitions we have already loaded.
llvm::SmallVector<MacroDefinition *, 16> MacroDefinitionsLoaded;
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=135554&r1=135553&r2=135554&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Jul 19 20:10:58 2011
@@ -2188,6 +2188,14 @@
case SELECTOR_OFFSETS:
F.SelectorOffsets = (const uint32_t *)BlobStart;
F.LocalNumSelectors = Record[0];
+
+ // Introduce the global -> local mapping for identifiers within this AST
+ // file
+ GlobalSelectorMap.insert(
+ std::make_pair(getTotalNumSelectors() + 1,
+ std::make_pair(&F,
+ -getTotalNumSelectors())));
+ SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);
break;
case METHOD_POOL:
@@ -2538,15 +2546,13 @@
// Allocate space for loaded slocentries, identifiers, decls and types.
unsigned TotalNumTypes = 0,
- TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0,
- TotalNumSelectors = 0;
+ TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0;
for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries;
TotalNumTypes += Chain[I]->LocalNumTypes;
TotalNumPreallocatedPreprocessingEntities +=
Chain[I]->NumPreallocatedPreprocessingEntities;
TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions;
- TotalNumSelectors += Chain[I]->LocalNumSelectors;
}
TypesLoaded.resize(TotalNumTypes);
MacroDefinitionsLoaded.resize(TotalNumMacroDefs);
@@ -2559,7 +2565,6 @@
TotalNumPreallocatedPreprocessingEntities);
}
}
- SelectorsLoaded.resize(TotalNumSelectors);
// Preload SLocEntries.
for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) {
ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]);
@@ -4645,19 +4650,15 @@
if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) {
// Load this selector from the selector table.
- unsigned Idx = ID - 1;
- for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
- PerFileData &F = *Chain[N - I - 1];
- if (Idx < F.LocalNumSelectors) {
- ASTSelectorLookupTrait Trait(*this);
- SelectorsLoaded[ID - 1] =
- Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0);
- if (DeserializationListener)
- DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
- break;
- }
- Idx -= F.LocalNumSelectors;
- }
+ GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID);
+ assert(I != GlobalSelectorMap.end() && "Corrupted global selector map");
+ ASTSelectorLookupTrait Trait(*this);
+ PerFileData &F = *I->second.first;
+ unsigned Idx = ID - 1 + I->second.second;
+ SelectorsLoaded[ID - 1] =
+ Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0);
+ if (DeserializationListener)
+ DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]);
}
return SelectorsLoaded[ID - 1];
More information about the cfe-commits
mailing list