summaryrefslogtreecommitdiff
path: root/tools/llvm-cov/SourceCoverageView.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-09-18 23:37:27 +0000
committerVedant Kumar <vsk@apple.com>2017-09-18 23:37:27 +0000
commit2fbca6bfaecf6a7444f6afc1a9511187d781dc8e (patch)
tree7d5bbc572b755342003a4aec9224bcd35496dcc3 /tools/llvm-cov/SourceCoverageView.cpp
parent36409f332619d1ee97147eb96160f53a0d5f707d (diff)
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313595 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r--tools/llvm-cov/SourceCoverageView.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/tools/llvm-cov/SourceCoverageView.cpp b/tools/llvm-cov/SourceCoverageView.cpp
index 08a1c75a6f9..79c2c69571c 100644
--- a/tools/llvm-cov/SourceCoverageView.cpp
+++ b/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) {