diff options
author | Vedant Kumar <vsk@apple.com> | 2016-06-28 16:12:18 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2016-06-28 16:12:18 +0000 |
commit | cef440f7a7dcf17c3d658aa899f989cbfb021d98 (patch) | |
tree | 33dba2d0f346832c8adef8ad3da7bfc033e909a3 /llvm/tools/llvm-cov/CodeCoverage.cpp | |
parent | ebe840163878d5d5cc74645cc06e46e1f31b5b3c (diff) | |
download | bcm5719-llvm-cef440f7a7dcf17c3d658aa899f989cbfb021d98.tar.gz bcm5719-llvm-cef440f7a7dcf17c3d658aa899f989cbfb021d98.zip |
[llvm-cov] Avoid copying file paths multiple times (NFC)
llvm-svn: 274027
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 84318e3cd37..270a3408b7c 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<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; }; |