[llvm] 927919a - [llvm-cov] Simplify branch/MCDC subviews. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 27 16:00:42 PST 2024
Author: Fangrui Song
Date: 2024-01-27T16:00:37-08:00
New Revision: 927919ac34a2085a7a25814fea492ac462b0d4ac
URL: https://github.com/llvm/llvm-project/commit/927919ac34a2085a7a25814fea492ac462b0d4ac
DIFF: https://github.com/llvm/llvm-project/commit/927919ac34a2085a7a25814fea492ac462b0d4ac.diff
LOG: [llvm-cov] Simplify branch/MCDC subviews. NFC
Remove unneeded empty check and reundant copies. NFC
Added:
Modified:
llvm/tools/llvm-cov/CodeCoverage.cpp
llvm/tools/llvm-cov/SourceCoverageView.cpp
llvm/tools/llvm-cov/SourceCoverageView.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 6405bb15e70c4d..049e89d1a23003 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -343,17 +343,14 @@ void CodeCoverageTool::attachBranchSubViews(SourceCoverageView &View,
// Group branches that have the same line number into the same subview.
while (NextBranch != EndBranch) {
- std::vector<CountedRegion> ViewBranches;
+ SmallVector<CountedRegion, 0> ViewBranches;
unsigned CurrentLine = NextBranch->LineStart;
-
while (NextBranch != EndBranch && CurrentLine == NextBranch->LineStart)
ViewBranches.push_back(*NextBranch++);
- if (!ViewBranches.empty()) {
- auto SubView = SourceCoverageView::create(SourceName, File, ViewOpts,
- std::move(CoverageInfo));
- View.addBranch(CurrentLine, ViewBranches, std::move(SubView));
- }
+ View.addBranch(CurrentLine, std::move(ViewBranches),
+ SourceCoverageView::create(SourceName, File, ViewOpts,
+ std::move(CoverageInfo)));
}
}
@@ -371,20 +368,15 @@ void CodeCoverageTool::attachMCDCSubViews(SourceCoverageView &View,
// Group and process MCDC records that have the same line number into the
// same subview.
while (NextRecord != EndRecord) {
- std::vector<MCDCRecord> ViewMCDCRecords;
+ SmallVector<MCDCRecord, 0> ViewMCDCRecords;
unsigned CurrentLine = NextRecord->getDecisionRegion().LineEnd;
-
while (NextRecord != EndRecord &&
- CurrentLine == NextRecord->getDecisionRegion().LineEnd) {
+ CurrentLine == NextRecord->getDecisionRegion().LineEnd)
ViewMCDCRecords.push_back(*NextRecord++);
- }
-
- if (ViewMCDCRecords.empty())
- continue;
- auto SubView = SourceCoverageView::create(SourceName, File, ViewOpts,
- std::move(CoverageInfo));
- View.addMCDCRecord(CurrentLine, ViewMCDCRecords, std::move(SubView));
+ View.addMCDCRecord(CurrentLine, std::move(ViewMCDCRecords),
+ SourceCoverageView::create(SourceName, File, ViewOpts,
+ std::move(CoverageInfo)));
}
}
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 71edd5fec4280a..7c63de6f3c345a 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -175,15 +175,15 @@ void SourceCoverageView::addExpansion(
}
void SourceCoverageView::addBranch(unsigned Line,
- ArrayRef<CountedRegion> Regions,
+ SmallVector<CountedRegion, 0> Regions,
std::unique_ptr<SourceCoverageView> View) {
- BranchSubViews.emplace_back(Line, Regions, std::move(View));
+ BranchSubViews.emplace_back(Line, std::move(Regions), std::move(View));
}
void SourceCoverageView::addMCDCRecord(
- unsigned Line, ArrayRef<MCDCRecord> Records,
+ unsigned Line, SmallVector<MCDCRecord, 0> Records,
std::unique_ptr<SourceCoverageView> View) {
- MCDCSubViews.emplace_back(Line, Records, std::move(View));
+ MCDCSubViews.emplace_back(Line, std::move(Records), std::move(View));
}
void SourceCoverageView::addInstantiation(
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h
index 2e3fa8e627d83c..a874f7c6820d2b 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.h
+++ b/llvm/tools/llvm-cov/SourceCoverageView.h
@@ -69,13 +69,13 @@ struct InstantiationView {
/// A view that represents one or more branch regions on a given source line.
struct BranchView {
- std::vector<CountedRegion> Regions;
+ SmallVector<CountedRegion, 0> Regions;
std::unique_ptr<SourceCoverageView> View;
unsigned Line;
- BranchView(unsigned Line, ArrayRef<CountedRegion> Regions,
+ BranchView(unsigned Line, SmallVector<CountedRegion, 0> Regions,
std::unique_ptr<SourceCoverageView> View)
- : Regions(Regions), View(std::move(View)), Line(Line) {}
+ : Regions(std::move(Regions)), View(std::move(View)), Line(Line) {}
unsigned getLine() const { return Line; }
@@ -86,13 +86,13 @@ struct BranchView {
/// A view that represents one or more MCDC regions on a given source line.
struct MCDCView {
- std::vector<MCDCRecord> Records;
+ SmallVector<MCDCRecord, 0> Records;
std::unique_ptr<SourceCoverageView> View;
unsigned Line;
- MCDCView(unsigned Line, ArrayRef<MCDCRecord> Records,
+ MCDCView(unsigned Line, SmallVector<MCDCRecord, 0> Records,
std::unique_ptr<SourceCoverageView> View)
- : Records(Records), View(std::move(View)), Line(Line) {}
+ : Records(std::move(Records)), View(std::move(View)), Line(Line) {}
unsigned getLine() const { return Line; }
@@ -175,10 +175,10 @@ class SourceCoverageView {
std::vector<ExpansionView> ExpansionSubViews;
/// A container for all branches in the source on display.
- std::vector<BranchView> BranchSubViews;
+ SmallVector<BranchView, 0> BranchSubViews;
/// A container for all MCDC records in the source on display.
- std::vector<MCDCView> MCDCSubViews;
+ SmallVector<MCDCView, 0> MCDCSubViews;
/// A container for all instantiations (e.g template functions) in the source
/// on display.
@@ -304,11 +304,11 @@ class SourceCoverageView {
std::unique_ptr<SourceCoverageView> View);
/// Add a branch subview to this view.
- void addBranch(unsigned Line, ArrayRef<CountedRegion> Regions,
+ void addBranch(unsigned Line, SmallVector<CountedRegion, 0> Regions,
std::unique_ptr<SourceCoverageView> View);
/// Add an MCDC subview to this view.
- void addMCDCRecord(unsigned Line, ArrayRef<MCDCRecord> Records,
+ void addMCDCRecord(unsigned Line, SmallVector<MCDCRecord, 0> Records,
std::unique_ptr<SourceCoverageView> View);
/// Print the code coverage information for a specific portion of a
More information about the llvm-commits
mailing list