Skip to content

Commit

Permalink
Optimize moc: Preallocate space for list of preprocessed symbols.
Browse files Browse the repository at this point in the history
Without this, the symbol list is frequently reallocated. The value
is a guestimate. It corresponds to a block of memory with the size

262144 * 3 * 8 byte = ca. 6.3 megabytes

on a 64 bit machine. Looking at the final size of the symbol list,
this seems to fit the common case nicely.

Change-Id: Ib546a1ea479f2c6d8ab57be783cdf630f9b54f77
Reviewed-by: Marc Mutz <[email protected]>
  • Loading branch information
milianw authored and marc-kdab committed Dec 12, 2015
1 parent b894dfe commit 6cc79ad
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/tools/moc/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,10 @@ Symbols Preprocessor::preprocessed(const QByteArray &filename, QFile *file)

// phase 3: preprocess conditions and substitute macros
Symbols result;
// Preallocate some space to speed up the code below.
// The magic value was found by logging the final size
// and calculating an average when running moc over FOSS projects.
result.reserve(file->size() / 300000);
preprocess(filename, result);
mergeStringLiterals(&result);

Expand Down

0 comments on commit 6cc79ad

Please sign in to comment.