Skip to content

Commit

Permalink
[PGO]: reserve space for string to avoid excessive memory realloc/cop…
Browse files Browse the repository at this point in the history
…y (non linear)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256776 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
david-xl committed Jan 4, 2016
1 parent c5273dd commit 1de675f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1de675f

Please sign in to comment.