diff options
author | Michael Kruse <llvm@meinersbur.de> | 2018-12-10 15:16:37 +0000 |
---|---|---|
committer | Michael Kruse <llvm@meinersbur.de> | 2018-12-10 15:16:37 +0000 |
commit | 6b25c694332abf37b4fdd9e0c15139a921172b35 (patch) | |
tree | 81d7af924bf297ecd9e98024d32717754e80d499 /lib/Sema/SemaOverload.cpp | |
parent | 9db90514610de6a64b71f9fa7f115437aa3d83d3 (diff) |
Use zip_longest for iterator range comparisons. NFC.
Use zip_longest in two locations that compare iterator ranges.
zip_longest allows the iteration using a range-based for-loop and to be
symmetric over both ranges instead of prioritizing one over the other.
In that latter case code have to handle the case that the first is
longer than the second, the second is longer than the first, and both
are of the same length, which must partially be checked after the loop.
With zip_longest, this becomes an element comparison within the loop
like the comparison of the elements themselves. The symmetry makes it
clearer that neither the first and second iterators are handled
differently. The iterators are not event used directly anymore, just
the ranges.
Differential Revision: https://reviews.llvm.org/D55468
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348762 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 928a982e1f..7f627c270d 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -8977,25 +8977,28 @@ static Comparison compareEnableIfAttrs(const Sema &S, const FunctionDecl *Cand1, auto Cand1Attrs = Cand1->specific_attrs<EnableIfAttr>(); auto Cand2Attrs = Cand2->specific_attrs<EnableIfAttr>(); - auto Cand1I = Cand1Attrs.begin(); llvm::FoldingSetNodeID Cand1ID, Cand2ID; - for (EnableIfAttr *Cand2A : Cand2Attrs) { - Cand1ID.clear(); - Cand2ID.clear(); + for (auto Pair : zip_longest(Cand1Attrs, Cand2Attrs)) { + Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); + Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); // It's impossible for Cand1 to be better than (or equal to) Cand2 if Cand1 - // has fewer enable_if attributes than Cand2. - auto Cand1A = Cand1I++; - if (Cand1A == Cand1Attrs.end()) + // has fewer enable_if attributes than Cand2, and vice versa. + if (!Cand1A) return Comparison::Worse; + if (!Cand2A) + return Comparison::Better; + + Cand1ID.clear(); + Cand2ID.clear(); - Cand1A->getCond()->Profile(Cand1ID, S.getASTContext(), true); - Cand2A->getCond()->Profile(Cand2ID, S.getASTContext(), true); + (*Cand1A)->getCond()->Profile(Cand1ID, S.getASTContext(), true); + (*Cand2A)->getCond()->Profile(Cand2ID, S.getASTContext(), true); if (Cand1ID != Cand2ID) return Comparison::Worse; } - return Cand1I == Cand1Attrs.end() ? Comparison::Equal : Comparison::Better; + return Comparison::Equal; } static bool isBetterMultiversionCandidate(const OverloadCandidate &Cand1, |