Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions llvm/unittests/ProfileData/CoverageMappingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ namespace {
struct OutputFunctionCoverageData {
StringRef Name;
uint64_t Hash;
std::vector<std::string> FilenamesStorage;
std::vector<StringRef> Filenames;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not store the strings directly in Filenames rather than having a separate storage?

Suggested change
std::vector<StringRef> Filenames;
std::vector<std::string> Filenames;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filenames will be referenced by CoverageMappingRecord::Filenames, which is ArrayRef<StringRef>.

std::vector<CounterMappingRegion> Regions;
std::vector<CounterExpression> Expressions;

OutputFunctionCoverageData() : Hash(0) {}

OutputFunctionCoverageData(OutputFunctionCoverageData &&OFCD)
: Name(OFCD.Name), Hash(OFCD.Hash), Filenames(std::move(OFCD.Filenames)),
Regions(std::move(OFCD.Regions)) {}
: Name(OFCD.Name), Hash(OFCD.Hash),
FilenamesStorage(std::move(OFCD.FilenamesStorage)),
Filenames(std::move(OFCD.Filenames)), Regions(std::move(OFCD.Regions)) {
}

OutputFunctionCoverageData(const OutputFunctionCoverageData &) = delete;
OutputFunctionCoverageData &
Expand Down Expand Up @@ -135,7 +138,6 @@ struct InputFunctionCoverageData {
struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> {
bool UseMultipleReaders;
StringMap<unsigned> Files;
std::vector<std::string> Filenames;
std::vector<InputFunctionCoverageData> InputFunctions;
std::vector<OutputFunctionCoverageData> OutputFunctions;

Expand Down Expand Up @@ -233,13 +235,11 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> {

void readCoverageRegions(const std::string &Coverage,
OutputFunctionCoverageData &Data) {
// We will re-use the StringRef in duplicate tests, clear it to avoid
// clobber previous ones.
Filenames.clear();
Filenames.resize(Files.size() + 1);
// +1 here since `Files` (filename to index map) uses 1-based index.
Data.FilenamesStorage.resize(Files.size() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why + 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files (filename to index map) uses 1-based index. I don't know why it does so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to say this in a comment to make it clear the +1 isn't a bug

for (const auto &E : Files)
Filenames[E.getValue()] = E.getKey().str();
ArrayRef<std::string> FilenameRefs = llvm::ArrayRef(Filenames);
Data.FilenamesStorage[E.getValue()] = E.getKey().str();
ArrayRef<std::string> FilenameRefs = llvm::ArrayRef(Data.FilenamesStorage);
RawCoverageMappingReader Reader(Coverage, FilenameRefs, Data.Filenames,
Data.Expressions, Data.Regions);
EXPECT_THAT_ERROR(Reader.read(), Succeeded());
Expand Down