Skip to content

Commit

Permalink
[libFuzzer] reduce the number of vector resizes during merge (google/…
Browse files Browse the repository at this point in the history
…oss-fuzz#445)

llvm-svn=297551
  • Loading branch information
kcc committed Mar 11, 2017
1 parent c89fcb7 commit 8232de6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions llvm/lib/Fuzzer/FuzzerMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool Merger::Parse(std::istream &IS, bool ParseCoverage) {
size_t ExpectedStartMarker = 0;
const size_t kInvalidStartMarker = -1;
size_t LastSeenStartMarker = kInvalidStartMarker;
std::vector<uint32_t> TmpFeatures;
while (std::getline(IS, Line, '\n')) {
std::istringstream ISS1(Line);
std::string Marker;
Expand All @@ -95,11 +96,11 @@ bool Merger::Parse(std::istream &IS, bool ParseCoverage) {
return false;
LastSeenStartMarker = kInvalidStartMarker;
if (ParseCoverage) {
auto &V = Files[CurrentFileIdx].Features;
V.clear();
TmpFeatures.clear(); // use a vector from outer scope to avoid resizes.
while (ISS1 >> std::hex >> N)
V.push_back(N);
std::sort(V.begin(), V.end());
TmpFeatures.push_back(N);
std::sort(TmpFeatures.begin(), TmpFeatures.end());
Files[CurrentFileIdx].Features = TmpFeatures;
}
} else {
return false;
Expand Down Expand Up @@ -270,8 +271,8 @@ void Fuzzer::CrashResistantMerge(const std::vector<std::string> &Args,
IF.seekg(0, IF.beg);
M.ParseOrExit(IF, true);
IF.close();
Printf("MERGE-OUTER: consumed %zd bytes to parse the control file\n",
M.ApproximateMemoryConsumption());
Printf("MERGE-OUTER: consumed %zdMb (%zdMb rss) to parse the control file\n",
M.ApproximateMemoryConsumption() >> 20, GetPeakRSSMb());
std::vector<std::string> NewFiles;
size_t NumNewFeatures = M.Merge(&NewFiles);
Printf("MERGE-OUTER: %zd new files with %zd new features added\n",
Expand Down

0 comments on commit 8232de6

Please sign in to comment.