From 25836be2c482830889d3af5a7615e8f9236e7006 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 17 Dec 2017 23:52:45 +0000 Subject: Refactor overridden methods iteration to avoid double lookups. Convert most uses to range-for loops. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320954 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaCodeComplete.cpp | 5 +---- lib/Sema/SemaDecl.cpp | 10 ++++------ lib/Sema/SemaDeclCXX.cpp | 28 ++++++++++------------------ 3 files changed, 15 insertions(+), 28 deletions(-) (limited to 'lib/Sema') diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index ee11c5c94e..834e149d1a 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -3378,12 +3378,9 @@ static void MaybeAddOverrideCalls(Sema &S, DeclContext *InContext, return; PrintingPolicy Policy = getCompletionPrintingPolicy(S); - for (CXXMethodDecl::method_iterator M = Method->begin_overridden_methods(), - MEnd = Method->end_overridden_methods(); - M != MEnd; ++M) { + for (const CXXMethodDecl *Overridden : Method->overridden_methods()) { CodeCompletionBuilder Builder(Results.getAllocator(), Results.getCodeCompletionTUInfo()); - const CXXMethodDecl *Overridden = *M; if (Overridden->getCanonicalDecl() == Method->getCanonicalDecl()) continue; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 0b48a87c11..ec5ca69735 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7517,16 +7517,14 @@ enum OverrideErrorKind { OEK_All, OEK_NonDeleted, OEK_Deleted }; static void ReportOverrides(Sema& S, unsigned DiagID, const CXXMethodDecl *MD, OverrideErrorKind OEK = OEK_All) { S.Diag(MD->getLocation(), DiagID) << MD->getDeclName(); - for (CXXMethodDecl::method_iterator I = MD->begin_overridden_methods(), - E = MD->end_overridden_methods(); - I != E; ++I) { + for (const CXXMethodDecl *O : MD->overridden_methods()) { // This check (& the OEK parameter) could be replaced by a predicate, but // without lambdas that would be overkill. This is still nicer than writing // out the diag loop 3 times. if ((OEK == OEK_All) || - (OEK == OEK_NonDeleted && !(*I)->isDeleted()) || - (OEK == OEK_Deleted && (*I)->isDeleted())) - S.Diag((*I)->getLocation(), diag::note_overridden_virtual_function); + (OEK == OEK_NonDeleted && !O->isDeleted()) || + (OEK == OEK_Deleted && O->isDeleted())) + S.Diag(O->getLocation(), diag::note_overridden_virtual_function); } } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 497713f660..96472a0a70 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2748,8 +2748,7 @@ void Sema::CheckOverrideControl(NamedDecl *D) { // If a function is marked with the virt-specifier override and // does not override a member function of a base class, the program is // ill-formed. - bool HasOverriddenMethods = - MD->begin_overridden_methods() != MD->end_overridden_methods(); + bool HasOverriddenMethods = MD->size_overridden_methods() != 0; if (MD->hasAttr() && !HasOverriddenMethods) Diag(MD->getLocation(), diag::err_function_marked_override_not_overriding) << MD->getDeclName(); @@ -7424,10 +7423,8 @@ private: const llvm::SmallPtrSetImpl &Methods) { if (MD->size_overridden_methods() == 0) return Methods.count(MD->getCanonicalDecl()); - for (CXXMethodDecl::method_iterator I = MD->begin_overridden_methods(), - E = MD->end_overridden_methods(); - I != E; ++I) - if (CheckMostOverridenMethods(*I, Methods)) + for (const CXXMethodDecl *O : MD->overridden_methods()) + if (CheckMostOverridenMethods(O, Methods)) return true; return false; } @@ -7485,10 +7482,9 @@ static void AddMostOverridenMethods(const CXXMethodDecl *MD, llvm::SmallPtrSetImpl& Methods) { if (MD->size_overridden_methods() == 0) Methods.insert(MD->getCanonicalDecl()); - for (CXXMethodDecl::method_iterator I = MD->begin_overridden_methods(), - E = MD->end_overridden_methods(); - I != E; ++I) - AddMostOverridenMethods(*I, Methods); + else + for (const CXXMethodDecl *O : MD->overridden_methods()) + AddMostOverridenMethods(O, Methods); } /// \brief Check if a method overloads virtual methods in a base class without @@ -14062,15 +14058,13 @@ void Sema::SetDeclDeleted(Decl *Dcl, SourceLocation DelLoc) { // non-deleted virtual function. if (CXXMethodDecl *MD = dyn_cast(Fn)) { bool IssuedDiagnostic = false; - for (CXXMethodDecl::method_iterator I = MD->begin_overridden_methods(), - E = MD->end_overridden_methods(); - I != E; ++I) { + for (const CXXMethodDecl *O : MD->overridden_methods()) { if (!(*MD->begin_overridden_methods())->isDeleted()) { if (!IssuedDiagnostic) { Diag(DelLoc, diag::err_deleted_override) << MD->getDeclName(); IssuedDiagnostic = true; } - Diag((*I)->getLocation(), diag::note_overridden_virtual_function); + Diag(O->getLocation(), diag::note_overridden_virtual_function); } } // If this function was implicitly deleted because it was defaulted, @@ -14981,10 +14975,8 @@ void Sema::actOnDelayedExceptionSpecification(Decl *MethodD, if (Method->isVirtual()) { // Check overrides, which we previously had to delay. - for (CXXMethodDecl::method_iterator O = Method->begin_overridden_methods(), - OEnd = Method->end_overridden_methods(); - O != OEnd; ++O) - CheckOverridingFunctionExceptionSpec(Method, *O); + for (const CXXMethodDecl *O : Method->overridden_methods()) + CheckOverridingFunctionExceptionSpec(Method, O); } } -- cgit v1.2.3