]> granicus.if.org Git - llvm/commitdiff
llvm-cov: Simplify CounterMappingRegion, pushing logic to its user
authorJustin Bogner <mail@justinbogner.com>
Mon, 15 Sep 2014 03:41:01 +0000 (03:41 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 15 Sep 2014 03:41:01 +0000 (03:41 +0000)
A single function in SourceCoverageDataManager was the only user of
some of the comparisons in CounterMappingRegion, and at this point we
know that only one file is relevant. This lets us use slightly simpler
logic directly in the client.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217745 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/CoverageMapping.h
tools/llvm-cov/SourceCoverageDataManager.cpp

index 144fc521755da3079a409f19fb3dfb22c9284092..4c74436c0b720e6f6c81bd5b31f47a4a525c941c 100644 (file)
@@ -164,30 +164,26 @@ struct CounterMappingRegion {
         ColumnStart(ColumnStart), LineEnd(LineEnd), ColumnEnd(ColumnEnd),
         Kind(Kind), HasCodeBefore(HasCodeBefore) {}
 
+  inline std::pair<unsigned, unsigned> startLoc() const {
+    return std::pair<unsigned, unsigned>(LineStart, ColumnStart);
+  }
+
+  inline std::pair<unsigned, unsigned> endLoc() const {
+    return std::pair<unsigned, unsigned>(LineEnd, ColumnEnd);
+  }
+
   bool operator<(const CounterMappingRegion &Other) const {
     if (FileID != Other.FileID)
       return FileID < Other.FileID;
-    if (LineStart == Other.LineStart)
-      return ColumnStart < Other.ColumnStart;
-    return LineStart < Other.LineStart;
-  }
-
-  bool coversSameSource(const CounterMappingRegion &Other) const {
-    return FileID == Other.FileID &&
-        LineStart == Other.LineStart &&
-        ColumnStart == Other.ColumnStart &&
-        LineEnd == Other.LineEnd &&
-        ColumnEnd == Other.ColumnEnd;
+    return startLoc() < Other.startLoc();
   }
 
   bool contains(const CounterMappingRegion &Other) const {
     if (FileID != Other.FileID)
       return false;
-    if (LineStart > Other.LineStart ||
-        (LineStart == Other.LineStart && ColumnStart > Other.ColumnStart))
+    if (startLoc() > Other.startLoc())
       return false;
-    if (LineEnd < Other.LineEnd ||
-        (LineEnd == Other.LineEnd && ColumnEnd < Other.ColumnEnd))
+    if (endLoc() < Other.endLoc())
       return false;
     return true;
   }
index f64162822abd8b9c84570c78301322c424d7cc3b..6f7c8e5d9855ab03b301bc16029a8dedf16bb442 100644 (file)
@@ -26,13 +26,16 @@ ArrayRef<CountedRegion> SourceCoverageDataManager::getSourceRegions() {
   if (Uniqued || Regions.size() <= 1)
     return Regions;
 
-  // Sort.
-  std::sort(Regions.begin(), Regions.end());
+  // Sort the regions given that they're all in the same file at this point.
+  std::sort(Regions.begin(), Regions.end(),
+            [](const CountedRegion &LHS, const CountedRegion &RHS) {
+    return LHS.startLoc() < RHS.startLoc();
+  });
 
   // Merge duplicate source ranges and sum their execution counts.
   auto Prev = Regions.begin();
   for (auto I = Prev + 1, E = Regions.end(); I != E; ++I) {
-    if (I->coversSameSource(*Prev)) {
+    if (I->startLoc() == Prev->startLoc() && I->endLoc() == Prev->endLoc()) {
       Prev->ExecutionCount += I->ExecutionCount;
       continue;
     }