speedup checkpostfixoperator.cpp by caching commonly looked up stuff in the symbol database. Ticket: #4266

This commit is contained in:
Robert Reif 2012-11-12 06:16:38 +01:00 committed by Daniel Marjamäki
parent e5ebb49312
commit f82eff6589
1 changed files with 31 additions and 32 deletions

View File

@ -37,31 +37,28 @@ void CheckPostfixOperator::postfixOperator()
if (!_settings->isEnabled("performance")) if (!_settings->isEnabled("performance"))
return; return;
const Token *tok = _tokenizer->tokens();
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
// prevent crash if first token is ++ or -- const std::size_t functions = symbolDatabase->functionScopes.size();
if (Token::Match(tok, "++|--")) for (std::size_t i = 0; i < functions; ++i) {
tok = tok->next(); const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
for (; tok; tok = tok->next()) { if (tok->type() == Token::eIncDecOp) {
bool result = false; bool result = false;
if (Token::Match(tok, "++|--")) {
if (Token::Match(tok->tokAt(-2), ";|{|}") && Token::Match(tok->next(), ";|)|,")) { if (Token::Match(tok->tokAt(-2), ";|{|}") && Token::Match(tok->next(), ";|)|,")) {
result = true; result = true;
} else if (tok->strAt(-2) == ",") { } else if (tok->strAt(-2) == ",") {
int i(1); int ii(1);
while (tok->strAt(i) != ")" && tok->tokAt(i) != 0) { while (tok->strAt(ii) != ")" && tok->tokAt(ii) != 0) {
if (tok->strAt(i) == ";") { if (tok->strAt(ii) == ";") {
result = true; result = true;
break; break;
} }
++i; ++ii;
} }
} else if (tok->strAt(-2) == "<<" && tok->strAt(1) == "<<") { } else if (tok->strAt(-2) == "<<" && tok->strAt(1) == "<<") {
result = true; result = true;
} }
}
if (result && tok->previous()->varId()) { if (result && tok->previous()->varId()) {
const Variable *var = symbolDatabase->getVariableFromVarId(tok->previous()->varId()); const Variable *var = symbolDatabase->getVariableFromVarId(tok->previous()->varId());
@ -80,6 +77,8 @@ void CheckPostfixOperator::postfixOperator()
} }
} }
} }
}
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------