From 25710a66a94d003944bd616706c8cacdd3b49e23 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 18 Sep 2017 23:37:27 +0000 Subject: [llvm-cov] Simplify code to find the first uncovered segment. NFC. Now that that segment builder is guaranteed to produce segments in sorted order, we don't need a linear scan to get the right result. llvm-svn: 313595 --- llvm/tools/llvm-cov/SourceCoverageView.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'llvm/tools/llvm-cov/SourceCoverageView.cpp') diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp index 08a1c75..79c2c69 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp @@ -125,22 +125,16 @@ LineCoverageStats::LineCoverageStats( } unsigned SourceCoverageView::getFirstUncoveredLineNo() { - auto CheckIfUncovered = [](const coverage::CoverageSegment &S) { - return S.HasCount && S.Count == 0; - }; - // L is less than R if (1) it's an uncovered segment (has a 0 count), and (2) - // either R is not an uncovered segment, or L has a lower line number than R. const auto MinSegIt = - std::min_element(CoverageInfo.begin(), CoverageInfo.end(), - [CheckIfUncovered](const coverage::CoverageSegment &L, - const coverage::CoverageSegment &R) { - return (CheckIfUncovered(L) && - (!CheckIfUncovered(R) || (L.Line < R.Line))); - }); - if (CheckIfUncovered(*MinSegIt)) - return (*MinSegIt).Line; + find_if(CoverageInfo, [](const coverage::CoverageSegment &S) { + return S.HasCount && S.Count == 0; + }); + // There is no uncovered line, return zero. - return 0; + if (MinSegIt == CoverageInfo.end()) + return 0; + + return (*MinSegIt).Line; } std::string SourceCoverageView::formatCount(uint64_t N) { -- cgit v1.1