Optimize moc: Preallocate some space for tokenization results.

The value was found by looking at the common ratio between
input size and final size of the result list.

Change-Id: I5762c15156afad4a7b8c1538e886058b3b5b0673
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Milian Wolff 2015-05-30 23:08:49 +02:00
parent 978ee4e60e
commit 5b0f59c73d

View File

@ -154,6 +154,11 @@ bool Preprocessor::skipBranch()
Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocessor::TokenizeMode mode)
{
Symbols symbols;
// Preallocate some space to speed up the code below.
// The magic divisor value was found by calculating the average ratio between
// input size and the final size of symbols.
// This yielded a value of 16.x when compiling Qt Base.
symbols.reserve(input.size() / 16);
const char *begin = input.constData();
const char *data = begin;
while (*data) {