[llvm] r256776 - [PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 4 12:26:05 PST 2016
Author: davidxl
Date: Mon Jan 4 14:26:05 2016
New Revision: 256776
URL: http://llvm.org/viewvc/llvm-project?rev=256776&view=rev
Log:
[PGO]: reserve space for string to avoid excessive memory realloc/copy (non linear)
Modified:
llvm/trunk/lib/ProfileData/InstrProf.cpp
Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=256776&r1=256775&r2=256776&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Mon Jan 4 14:26:05 2016
@@ -168,6 +168,12 @@ int collectPGOFuncNameStrings(const std:
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;
More information about the llvm-commits
mailing list