From cef440f7a7dcf17c3d658aa899f989cbfb021d98 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 28 Jun 2016 16:12:18 +0000 Subject: [PATCH] [llvm-cov] Avoid copying file paths multiple times (NFC) llvm-svn: 274027 --- llvm/tools/llvm-cov/CodeCoverage.cpp | 15 +++++++++++++-- llvm/tools/llvm-cov/CoverageReport.cpp | 2 +- llvm/tools/llvm-cov/CoverageReport.h | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 84318e3cd37c..270a3408b7cf 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -48,6 +48,9 @@ public: /// \brief Print the error message to the error output stream. void error(const Twine &Message, StringRef Whence = ""); + /// \brief Append a reference to a private copy of \p Path into SourceFiles. + void addCollectedPath(const std::string &Path); + /// \brief Return a memory buffer for the given source file. ErrorOr getSourceFile(StringRef SourceFile); @@ -81,12 +84,15 @@ public: CoverageViewOptions ViewOpts; std::string PGOFilename; CoverageFiltersMatchAll Filters; - std::vector SourceFiles; + std::vector SourceFiles; std::vector>> LoadedSourceFiles; bool CompareFilenamesOnly; StringMap RemappedFilenames; std::string CoverageArch; + +private: + std::vector CollectedPaths; }; } @@ -97,6 +103,11 @@ void CodeCoverageTool::error(const Twine &Message, StringRef Whence) { errs() << Message << "\n"; } +void CodeCoverageTool::addCollectedPath(const std::string &Path) { + CollectedPaths.push_back(Path); + SourceFiles.emplace_back(CollectedPaths.back()); +} + ErrorOr CodeCoverageTool::getSourceFile(StringRef SourceFile) { // If we've remapped filenames, look up the real location for this file. @@ -356,7 +367,7 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { errs() << "error: " << File << ": " << EC.message(); return 1; } - SourceFiles.push_back(Path.str()); + addCollectedPath(Path.str()); } return 0; }; diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp index ed01a2e154f1..10e53b3f1f72 100644 --- a/llvm/tools/llvm-cov/CoverageReport.cpp +++ b/llvm/tools/llvm-cov/CoverageReport.cpp @@ -171,7 +171,7 @@ void CoverageReport::render(const FunctionCoverageSummary &Function, OS << "\n"; } -void CoverageReport::renderFunctionReports(ArrayRef Files, +void CoverageReport::renderFunctionReports(ArrayRef Files, raw_ostream &OS) { adjustColumnWidths(Coverage.get()); bool isFirst = true; diff --git a/llvm/tools/llvm-cov/CoverageReport.h b/llvm/tools/llvm-cov/CoverageReport.h index 7ec3df90b8f9..bb3d734b52a5 100644 --- a/llvm/tools/llvm-cov/CoverageReport.h +++ b/llvm/tools/llvm-cov/CoverageReport.h @@ -32,7 +32,7 @@ public: std::unique_ptr Coverage) : Options(Options), Coverage(std::move(Coverage)) {} - void renderFunctionReports(ArrayRef Files, raw_ostream &OS); + void renderFunctionReports(ArrayRef Files, raw_ostream &OS); void renderFileReports(raw_ostream &OS); };