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:
parent
a545715c83
commit
f337e22401
@ -547,7 +547,10 @@ void Preprocessor::macroExpand(Symbols *into, Preprocessor *that, Symbols &toExp
|
|||||||
Symbols newSyms = macroExpandIdentifier(that, symbols, lineNum, ¯o);
|
Symbols newSyms = macroExpandIdentifier(that, symbols, lineNum, ¯o);
|
||||||
|
|
||||||
if (macro.isEmpty()) {
|
if (macro.isEmpty()) {
|
||||||
*into += newSyms;
|
// not a macro
|
||||||
|
Symbol s = symbols.symbol();
|
||||||
|
s.lineNum = lineNum;
|
||||||
|
*into += s;
|
||||||
} else {
|
} else {
|
||||||
SafeSymbols sf;
|
SafeSymbols sf;
|
||||||
sf.symbols = newSyms;
|
sf.symbols = newSyms;
|
||||||
@ -573,10 +576,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
|
|||||||
|
|
||||||
// not a macro
|
// not a macro
|
||||||
if (s.token != PP_IDENTIFIER || !that->macros.contains(s) || symbols.dontReplaceSymbol(s.lexem())) {
|
if (s.token != PP_IDENTIFIER || !that->macros.contains(s) || symbols.dontReplaceSymbol(s.lexem())) {
|
||||||
Symbols syms;
|
return Symbols();
|
||||||
syms += s;
|
|
||||||
syms.last().lineNum = lineNum;
|
|
||||||
return syms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Macro ¯o = that->macros.value(s);
|
const Macro ¯o = that->macros.value(s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user