[llvm] r217745 - llvm-cov: Simplify CounterMappingRegion, pushing logic to its user

Justin Bogner mail at justinbogner.com
Sun Sep 14 20:41:02 PDT 2014


Author: bogner
Date: Sun Sep 14 22:41:01 2014
New Revision: 217745

URL: http://llvm.org/viewvc/llvm-project?rev=217745&view=rev
Log:
llvm-cov: Simplify CounterMappingRegion, pushing logic to its user

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.

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

Modified: llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/CoverageMapping.h?rev=217745&r1=217744&r2=217745&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/CoverageMapping.h (original)
+++ llvm/trunk/include/llvm/ProfileData/CoverageMapping.h Sun Sep 14 22:41:01 2014
@@ -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;
   }

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp?rev=217745&r1=217744&r2=217745&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageDataManager.cpp Sun Sep 14 22:41:01 2014
@@ -26,13 +26,16 @@ ArrayRef<CountedRegion> SourceCoverageDa
   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;
     }





More information about the llvm-commits mailing list