speedup checkpostfixoperator.cpp by caching commonly looked up stuff in the symbol database. Ticket: #4266
This commit is contained in:
parent
e5ebb49312
commit
f82eff6589
|
@ -37,31 +37,28 @@ void CheckPostfixOperator::postfixOperator()
|
|||
if (!_settings->isEnabled("performance"))
|
||||
return;
|
||||
|
||||
const Token *tok = _tokenizer->tokens();
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
|
||||
// prevent crash if first token is ++ or --
|
||||
if (Token::Match(tok, "++|--"))
|
||||
tok = tok->next();
|
||||
|
||||
for (; tok; tok = tok->next()) {
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->type() == Token::eIncDecOp) {
|
||||
bool result = false;
|
||||
if (Token::Match(tok, "++|--")) {
|
||||
if (Token::Match(tok->tokAt(-2), ";|{|}") && Token::Match(tok->next(), ";|)|,")) {
|
||||
result = true;
|
||||
} else if (tok->strAt(-2) == ",") {
|
||||
int i(1);
|
||||
while (tok->strAt(i) != ")" && tok->tokAt(i) != 0) {
|
||||
if (tok->strAt(i) == ";") {
|
||||
int ii(1);
|
||||
while (tok->strAt(ii) != ")" && tok->tokAt(ii) != 0) {
|
||||
if (tok->strAt(ii) == ";") {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
++ii;
|
||||
}
|
||||
} else if (tok->strAt(-2) == "<<" && tok->strAt(1) == "<<") {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (result && tok->previous()->varId()) {
|
||||
const Variable *var = symbolDatabase->getVariableFromVarId(tok->previous()->varId());
|
||||
|
@ -80,6 +77,8 @@ void CheckPostfixOperator::postfixOperator()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue