Optimize moc: Remove another temporary list allocation.

In the common case, macroExpandIdentifier was called in the
"not a macro" case, and a temporary vector with a single item was
allocated. Now, we catch this common case at the caller site
and put the single item directly into the result set, bypassing
the temporary list.

Change-Id: I71d92afc486ccdaae5930405d028f53f48073b8c
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Milian Wolff 2015-05-30 23:20:33 +02:00
parent a545715c83
commit f337e22401

View File

@ -547,7 +547,10 @@ void Preprocessor::macroExpand(Symbols *into, Preprocessor *that, Symbols &toExp
Symbols newSyms = macroExpandIdentifier(that, symbols, lineNum, &macro);
if (macro.isEmpty()) {
*into += newSyms;
// not a macro
Symbol s = symbols.symbol();
s.lineNum = lineNum;
*into += s;
} else {
SafeSymbols sf;
sf.symbols = newSyms;
@ -573,10 +576,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
// not a macro
if (s.token != PP_IDENTIFIER || !that->macros.contains(s) || symbols.dontReplaceSymbol(s.lexem())) {
Symbols syms;
syms += s;
syms.last().lineNum = lineNum;
return syms;
return Symbols();
}
const Macro &macro = that->macros.value(s);