[PATCH] D18756: [Coverage] Avoid unnecessary copying of an std::vector.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 02:15:39 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL266284: [Coverage] Avoid unnecessary copying of std::vector (authored by ikudrin).

Repository:
  rL LLVM

http://reviews.llvm.org/D18756

Files:
  llvm/trunk/lib/ProfileData/CoverageMapping.cpp

Index: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
===================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp
@@ -272,9 +272,11 @@
 };
 
 class SegmentBuilder {
-  std::vector<CoverageSegment> Segments;
+  std::vector<CoverageSegment> &Segments;
   SmallVector<const CountedRegion *, 8> ActiveRegions;
 
+  SegmentBuilder(std::vector<CoverageSegment> &Segments) : Segments(Segments) {}
+
   /// Start a segment with no count specified.
   void startSegment(unsigned Line, unsigned Col) {
     DEBUG(dbgs() << "Top level segment at " << Line << ":" << Col << "\n");
@@ -318,9 +320,7 @@
       startSegment(Line, Col, false, *ActiveRegions.back());
   }
 
-public:
-  /// Build a list of CoverageSegments from a sorted list of Regions.
-  std::vector<CoverageSegment> buildSegments(ArrayRef<CountedRegion> Regions) {
+  void buildSegmentsImpl(ArrayRef<CountedRegion> Regions) {
     const CountedRegion *PrevRegion = nullptr;
     for (const auto &Region : Regions) {
       // Pop any regions that end before this one starts.
@@ -341,6 +341,15 @@
     // Pop any regions that are left in the stack.
     while (!ActiveRegions.empty())
       popRegion();
+  }
+
+public:
+  /// Build a list of CoverageSegments from a sorted list of Regions.
+  static std::vector<CoverageSegment>
+  buildSegments(ArrayRef<CountedRegion> Regions) {
+    std::vector<CoverageSegment> Segments;
+    SegmentBuilder Builder(Segments);
+    Builder.buildSegmentsImpl(Regions);
     return Segments;
   }
 };
@@ -426,7 +435,7 @@
 
   sortNestedRegions(Regions.begin(), Regions.end());
   DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
-  FileCoverage.Segments = SegmentBuilder().buildSegments(Regions);
+  FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);
 
   return FileCoverage;
 }
@@ -468,7 +477,7 @@
 
   sortNestedRegions(Regions.begin(), Regions.end());
   DEBUG(dbgs() << "Emitting segments for function: " << Function.Name << "\n");
-  FunctionCoverage.Segments = SegmentBuilder().buildSegments(Regions);
+  FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
 
   return FunctionCoverage;
 }
@@ -488,7 +497,7 @@
   sortNestedRegions(Regions.begin(), Regions.end());
   DEBUG(dbgs() << "Emitting segments for expansion of file " << Expansion.FileID
                << "\n");
-  ExpansionCoverage.Segments = SegmentBuilder().buildSegments(Regions);
+  ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
 
   return ExpansionCoverage;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18756.53676.patch
Type: text/x-patch
Size: 2607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160414/63296039/attachment.bin>


More information about the llvm-commits mailing list