[PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)

llvm-svn: 256776
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 3c75269..dd5f04b 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -168,6 +168,12 @@
                               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;