diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-07-20 00:27:43 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-07-20 00:27:43 +0000 |
commit | 96e973f2be14c9b82136f74b4108465d24894fea (patch) | |
tree | c4ea51ffca26c92e0bee00ed70ee2e85f84f0ab6 /lib/Serialization | |
parent | 19207f1e5f51261a33492602501fb7ada50ea546 (diff) |
Use a ContinuousRangeMap to map from the global declaration ID in the
AST reader down to the AST file + local ID within that file, rather
than lamely walking the PCH chain. There's no actual functionality
change now, but this is cleaner and more general.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135548 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 11 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderDecl.cpp | 15 |
2 files changed, 13 insertions, 13 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 61c3a5c2ff..9f3d7504c7 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2046,6 +2046,13 @@ ASTReader::ReadASTBlock(PerFileData &F) { } F.DeclOffsets = (const uint32_t *)BlobStart; F.LocalNumDecls = Record[0]; + + // Introduce the global -> local mapping for declarations within this + GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, + std::make_pair(&F, + -getTotalNumDecls()))); + DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); + break; case TU_UPDATE_LEXICAL: { @@ -2522,14 +2529,13 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, } // Allocate space for loaded slocentries, identifiers, decls and types. - unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, + unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, TotalNumSelectors = 0; for (unsigned I = 0, N = Chain.size(); I != N; ++I) { TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; TotalNumTypes += Chain[I]->LocalNumTypes; - TotalNumDecls += Chain[I]->LocalNumDecls; TotalNumPreallocatedPreprocessingEntities += Chain[I]->NumPreallocatedPreprocessingEntities; TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; @@ -2537,7 +2543,6 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, } IdentifiersLoaded.resize(TotalNumIdentifiers); TypesLoaded.resize(TotalNumTypes); - DeclsLoaded.resize(TotalNumDecls); MacroDefinitionsLoaded.resize(TotalNumMacroDefs); if (PP) { if (TotalNumIdentifiers > 0) diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 24ab544dcd..4f55d4625d 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1408,7 +1408,7 @@ static bool isConsumerInterestedIn(Decl *D) { return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D); } -/// \brief Get the correct cursor and offset for loading a type. +/// \brief Get the correct cursor and offset for loading a declaration. ASTReader::RecordLocation ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) { // See if there's an override. @@ -1416,15 +1416,10 @@ ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) { if (It != ReplacedDecls.end()) return RecordLocation(It->second.first, It->second.second); - PerFileData *F = 0; - for (unsigned I = 0, N = Chain.size(); I != N; ++I) { - F = Chain[N - I - 1]; - if (Index < F->LocalNumDecls) - break; - Index -= F->LocalNumDecls; - } - assert(F && F->LocalNumDecls > Index && "Broken chain"); - return RecordLocation(F, F->DeclOffsets[Index]); + GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); + assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); + return RecordLocation(I->second.first, + I->second.first->DeclOffsets[Index + I->second.second]); } void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { |