diff options
author | Serge Guelton <sguelton@redhat.com> | 2019-06-05 06:35:10 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@redhat.com> | 2019-06-05 06:35:10 +0000 |
commit | 4cd07dbeec9811a98efbc0ed3518e78dc38c0f53 (patch) | |
tree | 18aba521659274a4335591d19321042fef6ffc89 /clang/lib/CodeGen/CoverageMappingGen.cpp | |
parent | a3e16719c46aff109a6902c32787c06831c0e61d (diff) | |
download | bcm5719-llvm-4cd07dbeec9811a98efbc0ed3518e78dc38c0f53.tar.gz bcm5719-llvm-4cd07dbeec9811a98efbc0ed3518e78dc38c0f53.zip |
Reduce memory consumption of coverage dumps
Avoiding an intermediate join operation removes the need for an
intermediate buffer that may be quite large, as showcased by
https://bugs.llvm.org/show_bug.cgi?id=41965
Differential Revision: https://reviews.llvm.org/D62623
llvm-svn: 362584
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index ad014b5a17e..d900c7b2383 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1388,10 +1388,19 @@ void CoverageMappingModuleGen::emit() { std::string FilenamesAndCoverageMappings; llvm::raw_string_ostream OS(FilenamesAndCoverageMappings); CoverageFilenamesSectionWriter(FilenameRefs).write(OS); - std::string RawCoverageMappings = - llvm::join(CoverageMappings.begin(), CoverageMappings.end(), ""); - OS << RawCoverageMappings; - size_t CoverageMappingSize = RawCoverageMappings.size(); + + // Stream the content of CoverageMappings to OS while keeping + // memory consumption under control. + size_t CoverageMappingSize = 0; + for (auto &S : CoverageMappings) { + CoverageMappingSize += S.size(); + OS << S; + S.clear(); + S.shrink_to_fit(); + } + CoverageMappings.clear(); + CoverageMappings.shrink_to_fit(); + size_t FilenamesSize = OS.str().size() - CoverageMappingSize; // Append extra zeroes if necessary to ensure that the size of the filenames // and coverage mappings is a multiple of 8. |