llvm.org GIT mirror llvm / ae73627
[llvm-profdata] Clean up the way we create the input filenames buffer (NFC) Create the buffer before calling parseInputFilenamesFile(), and add a comment explaining why this is done. Thanks to David Li for the suggestion! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271756 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 3 years ago
1 changed file(s) with 15 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
223223 }
224224
225225 static std::unique_ptr
226 parseInputFilenamesFile(const StringRef &InputFilenamesFile,
227 WeightedFileVector &WFV) {
226 getInputFilenamesFileBuf(const StringRef &InputFilenamesFile) {
228227 if (InputFilenamesFile == "")
229228 return {};
230229
232231 if (!BufOrError)
233232 exitWithErrorCode(BufOrError.getError(), InputFilenamesFile);
234233
235 std::unique_ptr Buffer = std::move(*BufOrError);
234 return std::move(*BufOrError);
235 }
236
237 static void parseInputFilenamesFile(MemoryBuffer *Buffer,
238 WeightedFileVector &WFV) {
239 if (!Buffer)
240 return;
241
242 SmallVector Entries;
236243 StringRef Data = Buffer->getBuffer();
237
238 SmallVector Entries;
239244 Data.split(Entries, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
240245 for (const StringRef &FileWeightEntry : Entries) {
241246 StringRef SanitizedEntry = FileWeightEntry.trim(" \t\v\f\r");
248253 else
249254 WFV.emplace_back(parseWeightedFile(SanitizedEntry));
250255 }
251
252 return Buffer;
253256 }
254257
255258 static int merge_main(int argc, const char *argv[]) {
292295 WeightedInputs.push_back(WeightedFile(Filename, 1));
293296 for (StringRef WeightedFilename : WeightedInputFilenames)
294297 WeightedInputs.push_back(parseWeightedFile(WeightedFilename));
295 auto Buf = parseInputFilenamesFile(InputFilenamesFile, WeightedInputs);
298
299 // Make sure that the file buffer stays alive for the duration of the
300 // weighted input vector's lifetime.
301 auto Buffer = getInputFilenamesFileBuf(InputFilenamesFile);
302 parseInputFilenamesFile(Buffer.get(), WeightedInputs);
296303
297304 if (WeightedInputs.empty())
298305 exitWithError("No input files specified. See " +