[llvm] r274027 - [llvm-cov] Avoid copying file paths multiple times (NFC)
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 28 09:12:18 PDT 2016
Author: vedantk
Date: Tue Jun 28 11:12:18 2016
New Revision: 274027
URL: http://llvm.org/viewvc/llvm-project?rev=274027&view=rev
Log:
[llvm-cov] Avoid copying file paths multiple times (NFC)
Modified:
llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
llvm/trunk/tools/llvm-cov/CoverageReport.cpp
llvm/trunk/tools/llvm-cov/CoverageReport.h
Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=274027&r1=274026&r2=274027&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Tue Jun 28 11:12:18 2016
@@ -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
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, i
errs() << "error: " << File << ": " << EC.message();
return 1;
}
- SourceFiles.push_back(Path.str());
+ addCollectedPath(Path.str());
}
return 0;
};
Modified: llvm/trunk/tools/llvm-cov/CoverageReport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.cpp?rev=274027&r1=274026&r2=274027&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.cpp Tue Jun 28 11:12:18 2016
@@ -171,7 +171,7 @@ void CoverageReport::render(const Functi
OS << "\n";
}
-void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
+void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
raw_ostream &OS) {
adjustColumnWidths(Coverage.get());
bool isFirst = true;
Modified: llvm/trunk/tools/llvm-cov/CoverageReport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.h?rev=274027&r1=274026&r2=274027&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.h (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.h Tue Jun 28 11:12:18 2016
@@ -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);
};
More information about the llvm-commits
mailing list