speed up checkautovariables by caching commonly looked up stuff in the symbol database (#4266)
This commit is contained in:
parent
dd906a86a6
commit
5a7aae31f3
|
@ -83,13 +83,9 @@ void CheckAutoVariables::autoVariables()
|
|||
{
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
|
||||
std::list<Scope>::const_iterator scope;
|
||||
|
||||
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
|
||||
// only check functions
|
||||
if (scope->type != Scope::eFunction)
|
||||
continue;
|
||||
|
||||
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; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
// Critical assignment
|
||||
if (Token::Match(tok, "[;{}] %var% = & %var%") && isRefPtrArg(tok->next()->varId()) && isAutoVar(tok->tokAt(4)->varId())) {
|
||||
|
@ -162,18 +158,17 @@ void CheckAutoVariables::returnPointerToLocalArray()
|
|||
{
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
|
||||
std::list<Scope>::const_iterator scope;
|
||||
|
||||
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
|
||||
// only check functions
|
||||
if (scope->type != Scope::eFunction || !scope->function)
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
if (!scope->function)
|
||||
continue;
|
||||
|
||||
const Token *tok = scope->function->tokenDef;
|
||||
|
||||
// have we reached a function that returns a pointer
|
||||
if (tok->previous() && tok->previous()->str() == "*") {
|
||||
for (const Token *tok2 = scope->classStart; tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||
for (const Token *tok2 = scope->classStart->next(); tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||
// Return pointer to local array variable..
|
||||
if (Token::Match(tok2, "return %var% ;")) {
|
||||
const unsigned int varid = tok2->next()->varId();
|
||||
|
@ -287,18 +282,17 @@ void CheckAutoVariables::returnReference()
|
|||
{
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
|
||||
std::list<Scope>::const_iterator scope;
|
||||
|
||||
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
|
||||
// only check functions
|
||||
if (scope->type != Scope::eFunction || !scope->function)
|
||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
||||
for (std::size_t i = 0; i < functions; ++i) {
|
||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||
if (!scope->function)
|
||||
continue;
|
||||
|
||||
const Token *tok = scope->function->tokenDef;
|
||||
|
||||
// have we reached a function that returns a reference?
|
||||
if (tok->previous() && tok->previous()->str() == "&") {
|
||||
for (const Token *tok2 = scope->classStart; tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||
for (const Token *tok2 = scope->classStart->next(); tok2 && tok2 != scope->classEnd; tok2 = tok2->next()) {
|
||||
// return..
|
||||
if (Token::Match(tok2, "return %var% ;")) {
|
||||
// is the returned variable a local variable?
|
||||
|
|
Loading…
Reference in New Issue