Tokenizer: small speedup

This commit is contained in:
Daniel Marjamäki 2013-06-16 09:00:02 +02:00
parent a9bd6cf3df
commit 59478c15cf
1 changed files with 12 additions and 5 deletions

View File

@ -7414,11 +7414,14 @@ void Tokenizer::simplifyEnum()
bool hasClass = false; bool hasClass = false;
EnumValue *ev = NULL; EnumValue *ev = NULL;
int executableScopeLevel = 0;
if (!tok1) if (!tok1)
return; return;
for (Token *tok2 = tok1->next(); tok2; tok2 = tok2->next()) { for (Token *tok2 = tok1->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == "}") { if (tok2->str() == "}") {
--level; --level;
--executableScopeLevel;
if (level < 0) if (level < 0)
inScope = false; inScope = false;
@ -7442,6 +7445,9 @@ void Tokenizer::simplifyEnum()
// Not a duplicate enum.. // Not a duplicate enum..
++level; ++level;
if (executableScopeLevel > 0)
++executableScopeLevel;
// Create a copy of the shadow ids for the inner scope // Create a copy of the shadow ids for the inner scope
if (!shadowId.empty()) if (!shadowId.empty())
shadowId.push(shadowId.top()); shadowId.push(shadowId.top());
@ -7449,11 +7455,10 @@ void Tokenizer::simplifyEnum()
// are there shadow arguments? // are there shadow arguments?
if (Token::simpleMatch(tok2->previous(), ") {") || Token::simpleMatch(tok2->tokAt(-2), ") const {")) { if (Token::simpleMatch(tok2->previous(), ") {") || Token::simpleMatch(tok2->tokAt(-2), ") const {")) {
// Determine if this is a executable scope.. // Determine if this is a executable scope..
bool executableScope = false; if (executableScopeLevel <= 0) {
{ const Token *prev = tok2->previous();
const Token *prev = tok2->previous()->link();
while (prev) { while (prev) {
if (prev->str() == "}") if (prev->str() == "}" || prev->str() == ")")
prev = prev->link(); prev = prev->link();
else if (prev->str() == "{") { else if (prev->str() == "{") {
while ((prev = prev->previous()) && (prev->isName())); while ((prev = prev->previous()) && (prev->isName()));
@ -7464,9 +7469,11 @@ void Tokenizer::simplifyEnum()
} }
if (prev) if (prev)
executableScope = true; executableScopeLevel = 1;
} }
bool executableScope = (executableScopeLevel > 0);
std::set<std::string> shadowArg; std::set<std::string> shadowArg;
for (const Token* arg = tok2; arg && arg->str() != "("; arg = arg->previous()) { for (const Token* arg = tok2; arg && arg->str() != "("; arg = arg->previous()) {
if (Token::Match(arg->previous(), "%type%|*|& %type% [,)]") && if (Token::Match(arg->previous(), "%type%|*|& %type% [,)]") &&