From 0a0c03329583aef91eb942bbc481ab43762b9f4d Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 17 Apr 2017 17:16:19 +0000 Subject: [PATCH] Use default ref capture to simplify local lambdas, use a template to avoid std::function overhead, other cleanup llvm-svn: 300461 --- clang/lib/AST/ExternalASTMerger.cpp | 39 +++++++++++++---------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/clang/lib/AST/ExternalASTMerger.cpp b/clang/lib/AST/ExternalASTMerger.cpp index 2d4d0185ff2a..8849cfc3c80b 100644 --- a/clang/lib/AST/ExternalASTMerger.cpp +++ b/clang/lib/AST/ExternalASTMerger.cpp @@ -89,25 +89,21 @@ bool IsForwardDeclaration(Decl *D) { } } +template void ForEachMatchingDC( const DeclContext *DC, llvm::ArrayRef Importers, - std::function SourceDC)> - Callback) { + CallbackType Callback) { for (const ExternalASTMerger::ImporterPair &IP : Importers) { - Source SourceTU( - IP.Forward->getFromContext().getTranslationUnitDecl()); - Source SourceDC = - LookupSameContext(SourceTU, DC, *IP.Reverse); - if (SourceDC.get()) { + Source SourceTU = + IP.Forward->getFromContext().getTranslationUnitDecl(); + if (auto SourceDC = LookupSameContext(SourceTU, DC, *IP.Reverse)) Callback(IP, SourceDC); - } } } bool HasDeclOfSameType(llvm::ArrayRef Decls, const Candidate &C) { - return std::any_of(Decls.begin(), Decls.end(), [&C](const Candidate &D) { + return llvm::any_of(Decls, [&](const Candidate &D) { return C.first.get()->getKind() == D.first.get()->getKind(); }); } @@ -139,15 +135,15 @@ bool ExternalASTMerger::FindExternalVisibleDeclsByName(const DeclContext *DC, } }; - ForEachMatchingDC(DC, Importers, [Name, &FilterFoundDecl]( - const ImporterPair &IP, - Source SourceDC) { - DeclarationName FromName = IP.Reverse->Import(Name); - DeclContextLookupResult Result = SourceDC.get()->lookup(FromName); - for (NamedDecl *FromD : Result) { - FilterFoundDecl(std::make_pair(FromD, IP.Forward.get())); - } - }); + ForEachMatchingDC( + DC, Importers, + [&](const ImporterPair &IP, Source SourceDC) { + DeclarationName FromName = IP.Reverse->Import(Name); + DeclContextLookupResult Result = SourceDC.get()->lookup(FromName); + for (NamedDecl *FromD : Result) { + FilterFoundDecl(std::make_pair(FromD, IP.Forward.get())); + } + }); llvm::ArrayRef DeclsToReport = CompleteDecls.empty() ? ForwardDecls : CompleteDecls; @@ -170,15 +166,14 @@ void ExternalASTMerger::FindExternalLexicalDecls( const DeclContext *DC, llvm::function_ref IsKindWeWant, SmallVectorImpl &Result) { ForEachMatchingDC( - DC, Importers, [DC, IsKindWeWant](const ImporterPair &IP, - Source SourceDC) { + DC, Importers, + [&](const ImporterPair &IP, Source SourceDC) { for (const Decl *SourceDecl : SourceDC.get()->decls()) { if (IsKindWeWant(SourceDecl->getKind())) { Decl *ImportedDecl = IP.Forward->Import(const_cast(SourceDecl)); assert(ImportedDecl->getDeclContext() == DC); (void)ImportedDecl; - (void)DC; } } });