summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-01-04 20:26:05 +0000
committerXinliang David Li <davidxl@google.com>2016-01-04 20:26:05 +0000
commit13ea29b5a14dbcb99f8bed90da3825bc78e8203f (patch)
treee8074583baca9fff38343201cc7725e141e42624 /llvm/lib/ProfileData
parent3da5672755d3aa9ca7e0ae7db36d8142911a1b3e (diff)
downloadbcm5719-llvm-13ea29b5a14dbcb99f8bed90da3825bc78e8203f.tar.gz
bcm5719-llvm-13ea29b5a14dbcb99f8bed90da3825bc78e8203f.zip
[PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)
llvm-svn: 256776
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp6
1 files changed, 6 insertions, 0 deletions
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<std::string> &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;
OpenPOWER on IntegriCloud