diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-07-20 00:59:32 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-07-20 00:59:32 +0000 |
commit | 19d2635d8c1ef0b0a78a050de756c00692299013 (patch) | |
tree | b257035e11777d1548632a907a7d98f96890dd19 /clang/lib/Serialization/ASTReader.cpp | |
parent | 170581488f69f99f74ebe612c29c633f07bdae4f (diff) | |
download | bcm5719-llvm-19d2635d8c1ef0b0a78a050de756c00692299013.tar.gz bcm5719-llvm-19d2635d8c1ef0b0a78a050de756c00692299013.zip |
Use a ContinuousRangeMap to map from the global identifier 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.
llvm-svn: 135551
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 9f3d7504c7f..7d031019acb 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2048,11 +2048,11 @@ ASTReader::ReadASTBlock(PerFileData &F) { F.LocalNumDecls = Record[0]; // Introduce the global -> local mapping for declarations within this + // AST file. GlobalDeclMap.insert(std::make_pair(getTotalNumDecls() + 1, std::make_pair(&F, -getTotalNumDecls()))); - DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); - + DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); break; case TU_UPDATE_LEXICAL: { @@ -2119,6 +2119,14 @@ ASTReader::ReadASTBlock(PerFileData &F) { } F.IdentifierOffsets = (const uint32_t *)BlobStart; F.LocalNumIdentifiers = Record[0]; + + // Introduce the global -> local mapping for identifiers within this AST + // file + GlobalIdentifierMap.insert( + std::make_pair(getTotalNumIdentifiers() + 1, + std::make_pair(&F, + -getTotalNumIdentifiers()))); + IdentifiersLoaded.resize(IdentifiersLoaded.size() +F.LocalNumIdentifiers); break; case EXTERNAL_DEFINITIONS: @@ -2529,24 +2537,21 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, } // Allocate space for loaded slocentries, identifiers, decls and types. - unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, + unsigned 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; TotalNumPreallocatedPreprocessingEntities += Chain[I]->NumPreallocatedPreprocessingEntities; TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; TotalNumSelectors += Chain[I]->LocalNumSelectors; } - IdentifiersLoaded.resize(TotalNumIdentifiers); TypesLoaded.resize(TotalNumTypes); MacroDefinitionsLoaded.resize(TotalNumMacroDefs); if (PP) { - if (TotalNumIdentifiers > 0) - PP->getHeaderSearchInfo().SetExternalLookup(this); + PP->getHeaderSearchInfo().SetExternalLookup(this); if (TotalNumPreallocatedPreprocessingEntities > 0) { if (!PP->getPreprocessingRecord()) PP->createPreprocessingRecord(true); @@ -4602,18 +4607,11 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { assert(PP && "Forgot to set Preprocessor ?"); ID -= 1; if (!IdentifiersLoaded[ID]) { - unsigned Index = ID; - const char *Str = 0; - for (unsigned I = 0, N = Chain.size(); I != N; ++I) { - PerFileData *F = Chain[N - I - 1]; - if (Index < F->LocalNumIdentifiers) { - uint32_t Offset = F->IdentifierOffsets[Index]; - Str = F->IdentifierTableData + Offset; - break; - } - Index -= F->LocalNumIdentifiers; - } - assert(Str && "Broken Chain"); + GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); + assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); + unsigned Index = ID + I->second.second; + const char *Str = I->second.first->IdentifierTableData + + I->second.first->IdentifierOffsets[Index]; // All of the strings in the AST file are preceded by a 16-bit length. // Extract that 16-bit length to avoid having to execute strlen(). |