]> granicus.if.org Git - llvm/commitdiff
[llvm-cov] Avoid copying file paths multiple times (NFC)
authorVedant Kumar <vsk@apple.com>
Tue, 28 Jun 2016 16:12:18 +0000 (16:12 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 28 Jun 2016 16:12:18 +0000 (16:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274027 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-cov/CodeCoverage.cpp
tools/llvm-cov/CoverageReport.cpp
tools/llvm-cov/CoverageReport.h

index 84318e3cd37ce0c9bf778792f2c655724830fc67..270a3408b7cf56510aefe3daeb3f32cb8ed5fb22 100644 (file)
@@ -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<const MemoryBuffer &> getSourceFile(StringRef SourceFile);
 
@@ -81,12 +84,15 @@ public:
   CoverageViewOptions ViewOpts;
   std::string PGOFilename;
   CoverageFiltersMatchAll Filters;
-  std::vector<std::string> SourceFiles;
+  std::vector<StringRef> SourceFiles;
   std::vector<std::pair<std::string, std::unique_ptr<MemoryBuffer>>>
       LoadedSourceFiles;
   bool CompareFilenamesOnly;
   StringMap<std::string> RemappedFilenames;
   std::string CoverageArch;
+
+private:
+  std::vector<std::string> 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<const MemoryBuffer &>
 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;
   };
index ed01a2e154f1ba364f31b31a229b872b46323123..10e53b3f1f723d7a1c501e2fb23d26280edfadb4 100644 (file)
@@ -171,7 +171,7 @@ void CoverageReport::render(const FunctionCoverageSummary &Function,
   OS << "\n";
 }
 
-void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
+void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
                                            raw_ostream &OS) {
   adjustColumnWidths(Coverage.get());
   bool isFirst = true;
index 7ec3df90b8f92d32dc10cceef06bfbbec75896fd..bb3d734b52a5483e928a535f70c121aad8cc6c9f 100644 (file)
@@ -32,7 +32,7 @@ public:
                  std::unique_ptr<coverage::CoverageMapping> Coverage)
       : Options(Options), Coverage(std::move(Coverage)) {}
 
-  void renderFunctionReports(ArrayRef<std::string> Files, raw_ostream &OS);
+  void renderFunctionReports(ArrayRef<StringRef> Files, raw_ostream &OS);
 
   void renderFileReports(raw_ostream &OS);
 };