From 1f6386b79bf5ac42b40363e7318b8651a510709f Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 26 Jan 2010 07:37:41 +0000 Subject: [PATCH] Avoid some unnecessary copying of unresolved lookup results. llvm-svn: 94531 --- clang/include/clang/AST/ExprCXX.h | 6 ++++++ clang/lib/Sema/SemaOverload.cpp | 28 ++++++++++++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 2b20b52b604d..ad3f4b1c91dd 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -1149,6 +1149,9 @@ public: decls_iterator decls_begin() const { return Results.begin(); } decls_iterator decls_end() const { return Results.end(); } + /// Retrieves the decls as an unresolved set. + const UnresolvedSetImpl &getDecls() { return Results; } + /// True if this declaration should be extended by /// argument-dependent lookup. bool requiresADL() const { return RequiresADL; } @@ -1805,6 +1808,9 @@ public: unsigned getNumDecls() const { return Results.size(); } + /// Retrieves the decls as an unresolved set. + const UnresolvedSetImpl &getDecls() { return Results; } + /// \brief True if this is an implicit access, i.e. one in which the /// member being accessed was not written in the source. The source /// location of the operator is invalid in this case. diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 0fba0c62281c..47a7d175196f 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -4903,36 +4903,34 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType, bool HasExplicitTemplateArgs = false; TemplateArgumentListInfo ExplicitTemplateArgs; - - llvm::SmallVector Fns; + const UnresolvedSetImpl *Fns; // Look into the overloaded expression. if (UnresolvedLookupExpr *UL = dyn_cast(OvlExpr)) { - Fns.append(UL->decls_begin(), UL->decls_end()); + Fns = &UL->getDecls(); if (UL->hasExplicitTemplateArgs()) { HasExplicitTemplateArgs = true; UL->copyTemplateArgumentsInto(ExplicitTemplateArgs); } } else if (UnresolvedMemberExpr *ME = dyn_cast(OvlExpr)) { - Fns.append(ME->decls_begin(), ME->decls_end()); + Fns = &ME->getDecls(); if (ME->hasExplicitTemplateArgs()) { HasExplicitTemplateArgs = true; ME->copyTemplateArgumentsInto(ExplicitTemplateArgs); } - } + } else return 0; // If we didn't actually find anything, we're done. - if (Fns.empty()) + if (Fns->empty()) return 0; // Look through all of the overloaded functions, searching for one // whose type matches exactly. llvm::SmallPtrSet Matches; bool FoundNonTemplateFunction = false; - for (llvm::SmallVectorImpl::iterator I = Fns.begin(), - E = Fns.end(); I != E; ++I) { + for (UnresolvedSetIterator I = Fns->begin(), E = Fns->end(); I != E; ++I) { // Look through any using declarations to find the underlying function. NamedDecl *Fn = (*I)->getUnderlyingDecl(); @@ -5088,35 +5086,33 @@ FunctionDecl *Sema::ResolveSingleFunctionTemplateSpecialization(Expr *From) { bool HasExplicitTemplateArgs = false; TemplateArgumentListInfo ExplicitTemplateArgs; - - llvm::SmallVector Fns; + const UnresolvedSetImpl *Fns; // Look into the overloaded expression. if (UnresolvedLookupExpr *UL = dyn_cast(OvlExpr)) { - Fns.append(UL->decls_begin(), UL->decls_end()); + Fns = &UL->getDecls(); if (UL->hasExplicitTemplateArgs()) { HasExplicitTemplateArgs = true; UL->copyTemplateArgumentsInto(ExplicitTemplateArgs); } } else if (UnresolvedMemberExpr *ME = dyn_cast(OvlExpr)) { - Fns.append(ME->decls_begin(), ME->decls_end()); + Fns = &ME->getDecls(); if (ME->hasExplicitTemplateArgs()) { HasExplicitTemplateArgs = true; ME->copyTemplateArgumentsInto(ExplicitTemplateArgs); } - } + } else return 0; // If we didn't actually find any template-ids, we're done. - if (Fns.empty() || !HasExplicitTemplateArgs) + if (Fns->empty() || !HasExplicitTemplateArgs) return 0; // Look through all of the overloaded functions, searching for one // whose type matches exactly. FunctionDecl *Matched = 0; - for (llvm::SmallVectorImpl::iterator I = Fns.begin(), - E = Fns.end(); I != E; ++I) { + for (UnresolvedSetIterator I = Fns->begin(), E = Fns->end(); I != E; ++I) { // C++0x [temp.arg.explicit]p3: // [...] In contexts where deduction is done and fails, or in contexts // where deduction is not done, if a template argument list is