Skip to content

Commit 927919a

Browse files
committed
[llvm-cov] Simplify branch/MCDC subviews. NFC
Remove unneeded empty check and reundant copies. NFC
1 parent 53fea6f commit 927919a

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed

llvm/tools/llvm-cov/CodeCoverage.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,14 @@ void CodeCoverageTool::attachBranchSubViews(SourceCoverageView &View,
343343

344344
// Group branches that have the same line number into the same subview.
345345
while (NextBranch != EndBranch) {
346-
std::vector<CountedRegion> ViewBranches;
346+
SmallVector<CountedRegion, 0> ViewBranches;
347347
unsigned CurrentLine = NextBranch->LineStart;
348-
349348
while (NextBranch != EndBranch && CurrentLine == NextBranch->LineStart)
350349
ViewBranches.push_back(*NextBranch++);
351350

352-
if (!ViewBranches.empty()) {
353-
auto SubView = SourceCoverageView::create(SourceName, File, ViewOpts,
354-
std::move(CoverageInfo));
355-
View.addBranch(CurrentLine, ViewBranches, std::move(SubView));
356-
}
351+
View.addBranch(CurrentLine, std::move(ViewBranches),
352+
SourceCoverageView::create(SourceName, File, ViewOpts,
353+
std::move(CoverageInfo)));
357354
}
358355
}
359356

@@ -371,20 +368,15 @@ void CodeCoverageTool::attachMCDCSubViews(SourceCoverageView &View,
371368
// Group and process MCDC records that have the same line number into the
372369
// same subview.
373370
while (NextRecord != EndRecord) {
374-
std::vector<MCDCRecord> ViewMCDCRecords;
371+
SmallVector<MCDCRecord, 0> ViewMCDCRecords;
375372
unsigned CurrentLine = NextRecord->getDecisionRegion().LineEnd;
376-
377373
while (NextRecord != EndRecord &&
378-
CurrentLine == NextRecord->getDecisionRegion().LineEnd) {
374+
CurrentLine == NextRecord->getDecisionRegion().LineEnd)
379375
ViewMCDCRecords.push_back(*NextRecord++);
380-
}
381-
382-
if (ViewMCDCRecords.empty())
383-
continue;
384376

385-
auto SubView = SourceCoverageView::create(SourceName, File, ViewOpts,
386-
std::move(CoverageInfo));
387-
View.addMCDCRecord(CurrentLine, ViewMCDCRecords, std::move(SubView));
377+
View.addMCDCRecord(CurrentLine, std::move(ViewMCDCRecords),
378+
SourceCoverageView::create(SourceName, File, ViewOpts,
379+
std::move(CoverageInfo)));
388380
}
389381
}
390382

llvm/tools/llvm-cov/SourceCoverageView.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ void SourceCoverageView::addExpansion(
175175
}
176176

177177
void SourceCoverageView::addBranch(unsigned Line,
178-
ArrayRef<CountedRegion> Regions,
178+
SmallVector<CountedRegion, 0> Regions,
179179
std::unique_ptr<SourceCoverageView> View) {
180-
BranchSubViews.emplace_back(Line, Regions, std::move(View));
180+
BranchSubViews.emplace_back(Line, std::move(Regions), std::move(View));
181181
}
182182

183183
void SourceCoverageView::addMCDCRecord(
184-
unsigned Line, ArrayRef<MCDCRecord> Records,
184+
unsigned Line, SmallVector<MCDCRecord, 0> Records,
185185
std::unique_ptr<SourceCoverageView> View) {
186-
MCDCSubViews.emplace_back(Line, Records, std::move(View));
186+
MCDCSubViews.emplace_back(Line, std::move(Records), std::move(View));
187187
}
188188

189189
void SourceCoverageView::addInstantiation(

llvm/tools/llvm-cov/SourceCoverageView.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ struct InstantiationView {
6969

7070
/// A view that represents one or more branch regions on a given source line.
7171
struct BranchView {
72-
std::vector<CountedRegion> Regions;
72+
SmallVector<CountedRegion, 0> Regions;
7373
std::unique_ptr<SourceCoverageView> View;
7474
unsigned Line;
7575

76-
BranchView(unsigned Line, ArrayRef<CountedRegion> Regions,
76+
BranchView(unsigned Line, SmallVector<CountedRegion, 0> Regions,
7777
std::unique_ptr<SourceCoverageView> View)
78-
: Regions(Regions), View(std::move(View)), Line(Line) {}
78+
: Regions(std::move(Regions)), View(std::move(View)), Line(Line) {}
7979

8080
unsigned getLine() const { return Line; }
8181

@@ -86,13 +86,13 @@ struct BranchView {
8686

8787
/// A view that represents one or more MCDC regions on a given source line.
8888
struct MCDCView {
89-
std::vector<MCDCRecord> Records;
89+
SmallVector<MCDCRecord, 0> Records;
9090
std::unique_ptr<SourceCoverageView> View;
9191
unsigned Line;
9292

93-
MCDCView(unsigned Line, ArrayRef<MCDCRecord> Records,
93+
MCDCView(unsigned Line, SmallVector<MCDCRecord, 0> Records,
9494
std::unique_ptr<SourceCoverageView> View)
95-
: Records(Records), View(std::move(View)), Line(Line) {}
95+
: Records(std::move(Records)), View(std::move(View)), Line(Line) {}
9696

9797
unsigned getLine() const { return Line; }
9898

@@ -175,10 +175,10 @@ class SourceCoverageView {
175175
std::vector<ExpansionView> ExpansionSubViews;
176176

177177
/// A container for all branches in the source on display.
178-
std::vector<BranchView> BranchSubViews;
178+
SmallVector<BranchView, 0> BranchSubViews;
179179

180180
/// A container for all MCDC records in the source on display.
181-
std::vector<MCDCView> MCDCSubViews;
181+
SmallVector<MCDCView, 0> MCDCSubViews;
182182

183183
/// A container for all instantiations (e.g template functions) in the source
184184
/// on display.
@@ -304,11 +304,11 @@ class SourceCoverageView {
304304
std::unique_ptr<SourceCoverageView> View);
305305

306306
/// Add a branch subview to this view.
307-
void addBranch(unsigned Line, ArrayRef<CountedRegion> Regions,
307+
void addBranch(unsigned Line, SmallVector<CountedRegion, 0> Regions,
308308
std::unique_ptr<SourceCoverageView> View);
309309

310310
/// Add an MCDC subview to this view.
311-
void addMCDCRecord(unsigned Line, ArrayRef<MCDCRecord> Records,
311+
void addMCDCRecord(unsigned Line, SmallVector<MCDCRecord, 0> Records,
312312
std::unique_ptr<SourceCoverageView> View);
313313

314314
/// Print the code coverage information for a specific portion of a

0 commit comments

Comments
 (0)