@@ -84,15 +84,19 @@ void IRGenModule::emitCoverageMaps(ArrayRef<const SILCoverageMap *> Mappings) {
84
84
llvm::getCoverageUnusedNamesVarName ());
85
85
}
86
86
87
- std::vector<StringRef> Files;
87
+ llvm::DenseMap<StringRef, unsigned > RawFileIndices;
88
+ llvm::SmallVector<StringRef, 8 > RawFiles;
88
89
for (const auto &M : Mappings) {
89
- if (std::find (Files.begin (), Files.end (), M->getFilename ()) == Files.end ())
90
- Files.push_back (M->getFilename ());
90
+ auto Filename = M->getFilename ();
91
+ auto Inserted = RawFileIndices.insert ({Filename, RawFiles.size ()}).second ;
92
+ if (!Inserted)
93
+ continue ;
94
+ RawFiles.push_back (Filename);
91
95
}
92
96
const auto &Remapper = getOptions ().CoveragePrefixMap ;
93
97
94
98
llvm::SmallVector<std::string, 8 > FilenameStrs;
95
- FilenameStrs.reserve (Files .size () + 1 );
99
+ FilenameStrs.reserve (RawFiles .size () + 1 );
96
100
97
101
// First element needs to be the current working directory. Note if this
98
102
// scheme ever changes, the FileID computation below will need updating.
@@ -103,7 +107,7 @@ void IRGenModule::emitCoverageMaps(ArrayRef<const SILCoverageMap *> Mappings) {
103
107
// Following elements are the filenames present. We use their relative path,
104
108
// which llvm-cov will turn back into absolute paths using the working
105
109
// directory element.
106
- for (auto Name : Files )
110
+ for (auto Name : RawFiles )
107
111
FilenameStrs.emplace_back (Remapper.remapPath (Name));
108
112
109
113
// Encode the filenames.
@@ -130,9 +134,11 @@ void IRGenModule::emitCoverageMaps(ArrayRef<const SILCoverageMap *> Mappings) {
130
134
131
135
// The file ID needs to be bumped by 1 to account for the working directory
132
136
// as the first element.
133
- unsigned FileID = 1 +
134
- std::find (Files.begin (), Files.end (), M->getFilename ()) -
135
- Files.begin ();
137
+ unsigned FileID = [&]() {
138
+ auto Result = RawFileIndices.find (M->getFilename ());
139
+ assert (Result != RawFileIndices.end ());
140
+ return Result->second + 1 ;
141
+ }();
136
142
assert (FileID < FilenameStrs.size ());
137
143
138
144
std::vector<CounterMappingRegion> Regions;
0 commit comments