[llvm] r266284 - [Coverage] Avoid unnecessary copying of std::vector
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 14 02:10:01 PDT 2016
Author: ikudrin
Date: Thu Apr 14 04:10:00 2016
New Revision: 266284
URL: http://llvm.org/viewvc/llvm-project?rev=266284&view=rev
Log:
[Coverage] Avoid unnecessary copying of std::vector
Approved by: Justin Bogner <mail at justinbogner.com>
Differential Revision: http://reviews.llvm.org/D18756
Modified:
llvm/trunk/lib/ProfileData/CoverageMapping.cpp
Modified: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMapping.cpp?rev=266284&r1=266283&r2=266284&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Thu Apr 14 04:10:00 2016
@@ -272,9 +272,11 @@ public:
};
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 @@ class SegmentBuilder {
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 @@ public:
// 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 @@ CoverageData CoverageMapping::getCoverag
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 @@ CoverageMapping::getCoverageForFunction(
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 @@ CoverageMapping::getCoverageForExpansion
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;
}
More information about the llvm-commits
mailing list