From: Xinliang David Li Date: Mon, 4 Jan 2016 20:26:05 +0000 (+0000) Subject: [PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear) X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=1de675f473fb5c392d06e03cec4e8ee621e544ae [PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256776 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 3c752699a27..dd5f04bee32 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/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;