diff options
author | Vedant Kumar <vsk@apple.com> | 2016-01-21 19:25:35 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2016-01-21 19:25:35 +0000 |
commit | ca3326c0d4aecdb37f64b01f03eeacf4d6c258c6 (patch) | |
tree | 2209f9e032dc6aa4df2c8c5a8ebe635edde6afc7 | |
parent | 950af1558f8e8e9f7b3ec10bb954a59545f87e18 (diff) | |
download | bcm5719-llvm-ca3326c0d4aecdb37f64b01f03eeacf4d6c258c6.tar.gz bcm5719-llvm-ca3326c0d4aecdb37f64b01f03eeacf4d6c258c6.zip |
[Coverage] Reduce complexity of adding function mapping records
Replace a string append operation in addFunctionMappingRecord with a
vector append. The existing behavior is quadratic in the worst case:
this patch makes it linear.
Differential Revision: http://reviews.llvm.org/D16395
llvm-svn: 258424
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 9 | ||||
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.h | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index a859ad97d06..979f5867a9f 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -15,6 +15,7 @@ #include "CodeGenFunction.h" #include "clang/AST/StmtVisitor.h" #include "clang/Lex/Lexer.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Optional.h" #include "llvm/ProfileData/CoverageMapping.h" #include "llvm/ProfileData/CoverageMappingReader.h" @@ -932,7 +933,7 @@ void CoverageMappingModuleGen::addFunctionMappingRecord( if (!IsUsed) FunctionNames.push_back( llvm::ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx))); - CoverageMappings += CoverageMapping; + CoverageMappings.push_back(CoverageMapping); if (CGM.getCodeGenOpts().DumpCoverageMapping) { // Dump the coverage mapping data for this function by decoding the @@ -978,8 +979,10 @@ void CoverageMappingModuleGen::emit() { std::string FilenamesAndCoverageMappings; llvm::raw_string_ostream OS(FilenamesAndCoverageMappings); CoverageFilenamesSectionWriter(FilenameRefs).write(OS); - OS << CoverageMappings; - size_t CoverageMappingSize = CoverageMappings.size(); + std::string RawCoverageMappings = + llvm::join(CoverageMappings.begin(), CoverageMappings.end(), ""); + OS << RawCoverageMappings; + size_t CoverageMappingSize = RawCoverageMappings.size(); 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. diff --git a/clang/lib/CodeGen/CoverageMappingGen.h b/clang/lib/CodeGen/CoverageMappingGen.h index 70aed842924..c202fe89934 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.h +++ b/clang/lib/CodeGen/CoverageMappingGen.h @@ -56,7 +56,7 @@ class CoverageMappingModuleGen { std::vector<llvm::Constant *> FunctionRecords; std::vector<llvm::Constant *> FunctionNames; llvm::StructType *FunctionRecordTy; - std::string CoverageMappings; + std::vector<std::string> CoverageMappings; public: CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo) |