diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-06 21:05:21 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-08-06 21:05:21 +0000 |
commit | f13c68d4b13e62d9b015698f67cab68088c60cd8 (patch) | |
tree | 7b9e760e346cf794fd545408529b52d0a70a26fc | |
parent | dc5370b9cc0e8c6f1bee0861cdf7d763d131d05d (diff) | |
download | bcm5719-llvm-f13c68d4b13e62d9b015698f67cab68088c60cd8.tar.gz bcm5719-llvm-f13c68d4b13e62d9b015698f67cab68088c60cd8.zip |
[modules] Remove redundant lookups into non-primary DeclContexts. These were made unnecessary by r244192.
llvm-svn: 244271
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 77 |
1 files changed, 13 insertions, 64 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 41294a82b26..c12894d773f 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -6343,7 +6343,7 @@ namespace { /// declaration context. class DeclContextNameLookupVisitor { ASTReader &Reader; - ArrayRef<const DeclContext *> Contexts; + const DeclContext *Context; DeclarationName Name; ASTDeclContextNameLookupTrait::DeclNameKey NameKey; unsigned NameHash; @@ -6352,50 +6352,25 @@ namespace { public: DeclContextNameLookupVisitor(ASTReader &Reader, + const DeclContext *Context, DeclarationName Name, SmallVectorImpl<NamedDecl *> &Decls, llvm::SmallPtrSetImpl<NamedDecl *> &DeclSet) - : Reader(Reader), Name(Name), + : Reader(Reader), Context(Context), Name(Name), NameKey(ASTDeclContextNameLookupTrait::GetInternalKey(Name)), NameHash(ASTDeclContextNameLookupTrait::ComputeHash(NameKey)), Decls(Decls), DeclSet(DeclSet) {} - void visitContexts(ArrayRef<const DeclContext*> Contexts) { - if (Contexts.empty()) - return; - this->Contexts = Contexts; - - // If we can definitively determine which module file to look into, - // only look there. Otherwise, look in all module files. - ModuleFile *Definitive; - if (Contexts.size() == 1 && - (Definitive = getDefinitiveModuleFileFor(Contexts[0], Reader))) { - (*this)(*Definitive); - } else { - Reader.getModuleManager().visit(*this); - } - } - bool operator()(ModuleFile &M) { // Check whether we have any visible declaration information for // this context in this module. - ModuleFile::DeclContextInfosMap::iterator Info; - bool FoundInfo = false; - for (auto *DC : Contexts) { - Info = M.DeclContextInfos.find(DC); - if (Info != M.DeclContextInfos.end() && - Info->second.NameLookupTableData) { - FoundInfo = true; - break; - } - } - - if (!FoundInfo) + auto Info = M.DeclContextInfos.find(Context); + if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) return false; // Look for this name within this module. ASTDeclContextNameLookupTable *LookupTable = - Info->second.NameLookupTableData; + Info->second.NameLookupTableData; ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find_hashed(NameKey, NameHash); if (Pos == LookupTable->end()) @@ -6442,40 +6417,14 @@ ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, SmallVector<NamedDecl *, 64> Decls; llvm::SmallPtrSet<NamedDecl*, 64> DeclSet; - // Compute the declaration contexts we need to look into. Multiple such - // declaration contexts occur when two declaration contexts from disjoint - // modules get merged, e.g., when two namespaces with the same name are - // independently defined in separate modules. - SmallVector<const DeclContext *, 2> Contexts; - Contexts.push_back(DC); - - if (DC->isNamespace()) { - auto Key = KeyDecls.find(const_cast<Decl *>(cast<Decl>(DC))); - if (Key != KeyDecls.end()) { - for (unsigned I = 0, N = Key->second.size(); I != N; ++I) - Contexts.push_back(cast<DeclContext>(GetDecl(Key->second[I]))); - } - } - - DeclContextNameLookupVisitor Visitor(*this, Name, Decls, DeclSet); - Visitor.visitContexts(Contexts); + DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls, DeclSet); - // If this might be an implicit special member function, then also search - // all merged definitions of the surrounding class. We need to search them - // individually, because finding an entity in one of them doesn't imply that - // we can't find a different entity in another one. - if (isa<CXXRecordDecl>(DC)) { - auto Merged = MergedLookups.find(DC); - if (Merged != MergedLookups.end()) { - for (unsigned I = 0; I != Merged->second.size(); ++I) { - const DeclContext *Context = Merged->second[I]; - Visitor.visitContexts(Context); - // We might have just added some more merged lookups. If so, our - // iterator is now invalid, so grab a fresh one before continuing. - Merged = MergedLookups.find(DC); - } - } - } + // If we can definitively determine which module file to look into, + // only look there. Otherwise, look in all module files. + if (ModuleFile *Definitive = getDefinitiveModuleFileFor(DC, *this)) + Visitor(*Definitive); + else + ModuleMgr.visit(Visitor); ++NumVisibleDeclContextsRead; SetExternalVisibleDeclsForName(DC, Name, Decls); |