From 13ea29b5a14dbcb99f8bed90da3825bc78e8203f Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Mon, 4 Jan 2016 20:26:05 +0000 Subject: [PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear) llvm-svn: 256776 --- llvm/lib/ProfileData/InstrProf.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/lib/ProfileData/InstrProf.cpp') diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 3c752699a27..dd5f04bee32 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -168,6 +168,12 @@ int collectPGOFuncNameStrings(const std::vector &NameStrs, bool doCompression, std::string &Result) { uint8_t Header[16], *P = Header; std::string UncompressedNameStrings; + size_t UncompressedStringLen = 0; + + for (auto NameStr : NameStrs) + UncompressedStringLen += (NameStr.length() + 1); + + UncompressedNameStrings.reserve(UncompressedStringLen + 1); for (auto NameStr : NameStrs) { UncompressedNameStrings += NameStr; -- cgit v1.2.3