From: Douglas Gregor Date: Wed, 20 Jul 2011 01:10:58 +0000 (+0000) Subject: Use a ContinuousRangeMap to map from the global selector ID in the AST X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96958cbe6fb423ab2446629ead5f1b138398433c;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135554 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 418925fce2..72bfb0f8a4 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -570,6 +570,15 @@ private: /// been loaded. llvm::SmallVector SelectorsLoaded; + typedef ContinuousRangeMap, 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 MacroDefinitionsLoaded; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 7d031019ac..3bb9177011 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2188,6 +2188,14 @@ ASTReader::ReadASTBlock(PerFileData &F) { 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 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, // 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 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, 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 @@ Selector ASTReader::DecodeSelector(unsigned ID) { 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];