[llvm] r313595 - [llvm-cov] Simplify code to find the first uncovered segment. NFC.

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 16:37:27 PDT 2017


Author: vedantk
Date: Mon Sep 18 16:37:27 2017
New Revision: 313595

URL: http://llvm.org/viewvc/llvm-project?rev=313595&view=rev
Log:
[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.

Modified:
    llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=313595&r1=313594&r2=313595&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Mon Sep 18 16:37:27 2017
@@ -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) {




More information about the llvm-commits mailing list