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,45 +37,44 @@ 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 ii(1);
int i(1); while (tok->strAt(ii) != ")" && tok->tokAt(ii) != 0) {
while (tok->strAt(i) != ")" && tok->tokAt(i) != 0) { if (tok->strAt(ii) == ";") {
if (tok->strAt(i) == ";") { result = true;
result = true; break;
break; }
++ii;
} }
++i; } else if (tok->strAt(-2) == "<<" && tok->strAt(1) == "<<") {
result = true;
} }
} else if (tok->strAt(-2) == "<<" && tok->strAt(1) == "<<") {
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());
if (!var || var->isPointer() || var->isArray() || var->isReference()) if (!var || var->isPointer() || var->isArray() || var->isReference())
continue; continue;
const Token *decltok = var->nameToken(); const Token *decltok = var->nameToken();
if (Token::Match(decltok->previous(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator")) { if (Token::Match(decltok->previous(), "iterator|const_iterator|reverse_iterator|const_reverse_iterator")) {
// the variable is an iterator // the variable is an iterator
postfixOperatorError(tok); postfixOperatorError(tok);
} else if (var->type()) { } else if (var->type()) {
// the variable is an instance of class // the variable is an instance of class
postfixOperatorError(tok); postfixOperatorError(tok);
}
}
} }
} }
} }