From 68087199629c612115be35f91a4e001875720c0a Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 18 Apr 2012 13:03:01 +0200 Subject: [PATCH] preprocessor: avoid using QVector += QVector. It destroys preallocation. See https://bugreports.qt-project.org/browse/QTBUG-25371. Change-Id: Idde09a07f250a347f8016d8fdb04cd00d031fe10 Reviewed-by: Thomas Hartmann --- src/libs/cplusplus/pp-engine.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index c6eed518796..b39f4141bb7 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -850,9 +850,10 @@ bool Preprocessor::handleFunctionLikeMacro(PPToken *tk, const Macro *macro, QVec } QVector expanded; + expanded.reserve(MAX_TOKEN_EXPANSION_COUNT); for (size_t i = 0, bodySize = body.size(); i < bodySize && expanded.size() < MAX_TOKEN_EXPANSION_COUNT; ++i) { int expandedSize = expanded.size(); - const PPToken &token = body[i]; + const PPToken &token = body.at(i); if (token.is(T_IDENTIFIER)) { const ByteArrayRef id = token.asByteArrayRef(); @@ -866,7 +867,7 @@ bool Preprocessor::handleFunctionLikeMacro(PPToken *tk, const Macro *macro, QVec goto exitNicely; } - QVector actualsForThisParam = actuals[j]; + QVector actualsForThisParam = actuals.at(j); if (id == "__VA_ARGS__" || (macro->isVariadic() && j + 1 == formals.size())) { unsigned lineno = 0; const char comma = ','; @@ -894,7 +895,8 @@ bool Preprocessor::handleFunctionLikeMacro(PPToken *tk, const Macro *macro, QVec newText.replace("\"", "\\\""); expanded.push_back(generateToken(T_STRING_LITERAL, newText.constData(), newText.size(), lineno, true)); } else { - expanded += actualsForThisParam; + for (int k = 0, kk = actualsForThisParam.size(); k < kk; ++k) + expanded += actualsForThisParam.at(k); } break; } @@ -923,6 +925,7 @@ exitNicely: expanded.push_front(forceWhitespacingToken); } body = expanded; + body.squeeze(); return true; }