diff options
author | Xinliang David Li <davidxl@google.com> | 2016-01-04 20:26:05 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-01-04 20:26:05 +0000 |
commit | 13ea29b5a14dbcb99f8bed90da3825bc78e8203f (patch) | |
tree | e8074583baca9fff38343201cc7725e141e42624 | |
parent | 3da5672755d3aa9ca7e0ae7db36d8142911a1b3e (diff) | |
download | bcm5719-llvm-13ea29b5a14dbcb99f8bed90da3825bc78e8203f.tar.gz bcm5719-llvm-13ea29b5a14dbcb99f8bed90da3825bc78e8203f.zip |
[PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)
llvm-svn: 256776
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 6 |
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; |