From 1de675f473fb5c392d06e03cec4e8ee621e544ae Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Mon, 4 Jan 2016 20:26:05 +0000 Subject: [PATCH] [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 --- lib/ProfileData/InstrProf.cpp | 6 ++++++ 1 file changed, 6 insertions(+) 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; -- 2.34.1