diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2015-05-30 23:19:21 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-07-13 22:27:01 +0000 |
commit | c19e67eb73c8db6a2d30a1260779d3221083382c (patch) | |
tree | c0ab09ecb5520310049601a847ce07bf66ddfad1 /src/tools/moc/preprocessor.cpp | |
parent | 4efd2ebb27bf0ed2d2a9f472c5b163640be195e6 (diff) |
Optimize moc: Remove temporary allocations during macro expansion.
Previously, a temporary list was allocated and then fed into the
bigger list of results. Now, we push data into the final list
directly, removing the overhead of the temporary allocation.
Change-Id: I9bea0fd3c23b1434b4be2728c60ac22a66908efc
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'src/tools/moc/preprocessor.cpp')
-rw-r--r-- | src/tools/moc/preprocessor.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index f253c49995..14850b3e0c 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -529,7 +529,7 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso return symbols; } -Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &index, +void Preprocessor::macroExpand(Symbols *into, Preprocessor *that, Symbols &toExpand, int &index, int lineNum, bool one, const QSet<QByteArray> &excludeSymbols) { SymbolStack symbols; @@ -539,16 +539,15 @@ Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &in sf.excludedSymbols = excludeSymbols; symbols.push(sf); - Symbols result; if (toExpand.isEmpty()) - return result; + return; for (;;) { QByteArray macro; Symbols newSyms = macroExpandIdentifier(that, symbols, lineNum, ¯o); if (macro.isEmpty()) { - result += newSyms; + *into += newSyms; } else { SafeSymbols sf; sf.symbols = newSyms; @@ -565,8 +564,6 @@ Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &in index = symbols.top().index; else index = toExpand.size(); - - return result; } @@ -653,7 +650,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym if (i == macro.symbols.size() - 1 || macro.symbols.at(i + 1).token != PP_HASHHASH) { Symbols arg = arguments.at(index); int idx = 1; - expansion += macroExpand(that, arg, idx, lineNum, false, symbols.excludeSymbols()); + macroExpand(&expansion, that, arg, idx, lineNum, false, symbols.excludeSymbols()); } else { expansion += arguments.at(index); } @@ -726,7 +723,7 @@ void Preprocessor::substituteUntilNewline(Symbols &substituted) while (hasNext()) { Token token = next(); if (token == PP_IDENTIFIER) { - substituted += macroExpand(this, symbols, index, symbol().lineNum, true); + macroExpand(&substituted, this, symbols, index, symbol().lineNum, true); } else if (token == PP_DEFINED) { bool braces = test(PP_LPAREN); next(PP_IDENTIFIER); @@ -1148,7 +1145,7 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) } case PP_IDENTIFIER: { // substitute macros - preprocessed += macroExpand(this, symbols, index, symbol().lineNum, true); + macroExpand(&preprocessed, this, symbols, index, symbol().lineNum, true); continue; } case PP_HASH: |