diff options
Diffstat (limited to 'lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | lib/CodeGen/CoverageMappingGen.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp index 35962c73d9a82..6d18027f16a80 100644 --- a/lib/CodeGen/CoverageMappingGen.cpp +++ b/lib/CodeGen/CoverageMappingGen.cpp @@ -1,9 +1,8 @@ //===--- CoverageMappingGen.cpp - Coverage mapping generation ---*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -244,7 +243,7 @@ public: ++Depth; FileLocs.push_back(std::make_pair(Loc, Depth)); } - std::stable_sort(FileLocs.begin(), FileLocs.end(), llvm::less_second()); + llvm::stable_sort(FileLocs, llvm::less_second()); for (const auto &FL : FileLocs) { SourceLocation Loc = FL.first; @@ -1282,7 +1281,7 @@ std::string getCoverageSection(const CodeGenModule &CGM) { std::string normalizeFilename(StringRef Filename) { llvm::SmallString<256> Path(Filename); llvm::sys::fs::make_absolute(Path); - llvm::sys::path::remove_dots(Path, /*remove_dot_dots=*/true); + llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true); return Path.str().str(); } @@ -1389,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. |