speed up checkmemoryleak by caching commonly looked up stuff in the symbol database (#4266)

This commit is contained in:
Robert Reif 2012-10-21 09:07:51 +02:00 committed by Daniel Marjamäki
parent 9bc2a62c1e
commit d1fad4b762
1 changed files with 36 additions and 45 deletions

View File

@ -541,12 +541,10 @@ void CheckMemoryLeakInFunction::parse_noreturn()
noreturn.insert("pthread_exit"); noreturn.insert("pthread_exit");
} }
std::list<Scope>::const_iterator scope;
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
// only check functions // only check functions
if (scope->type != Scope::eFunction) const std::size_t functions = symbolDatabase->functionScopes.size();
continue; for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
// parse this function to check if it contains an "exit" call.. // parse this function to check if it contains an "exit" call..
bool isNoreturn = false; bool isNoreturn = false;
@ -2125,12 +2123,10 @@ static bool isNoArgument(const SymbolDatabase* symbolDatabase, unsigned int vari
void CheckMemoryLeakInFunction::checkReallocUsage() void CheckMemoryLeakInFunction::checkReallocUsage()
{ {
std::list<Scope>::const_iterator scope;
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
// only check functions // only check functions
if (scope->type != Scope::eFunction) const std::size_t functions = symbolDatabase->functionScopes.size();
continue; for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
// Search for the "var = realloc(var, 100" pattern within this function // Search for the "var = realloc(var, 100" pattern within this function
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
@ -2200,10 +2196,9 @@ void CheckMemoryLeakInFunction::check()
parse_noreturn(); parse_noreturn();
// Check locking/unlocking of global resources.. // Check locking/unlocking of global resources..
for (std::list<Scope>::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { const std::size_t functions = symbolDatabase->functionScopes.size();
// only check functions for (std::size_t i = 0; i < functions; ++i) {
if (scope->type != Scope::eFunction) const Scope * scope = symbolDatabase->functionScopes[i];
continue;
checkScope(scope->classStart->next(), "", 0, scope->functionOf != NULL, 1); checkScope(scope->classStart->next(), "", 0, scope->functionOf != NULL, 1);
} }
@ -2270,11 +2265,10 @@ void CheckMemoryLeakInClass::check()
{ {
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
std::list<Scope>::const_iterator scope;
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
// only check classes and structures // only check classes and structures
if (scope->isClassOrStruct()) { const std::size_t classes = symbolDatabase->classAndStructScopes.size();
for (std::size_t i = 0; i < classes; ++i) {
const Scope * scope = symbolDatabase->classAndStructScopes[i];
std::list<Variable>::const_iterator var; std::list<Variable>::const_iterator var;
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) { for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
if (!var->isStatic() && var->isPointer()) { if (!var->isStatic() && var->isPointer()) {
@ -2302,7 +2296,6 @@ void CheckMemoryLeakInClass::check()
} }
} }
} }
}
} }
@ -2687,12 +2680,10 @@ void CheckMemoryLeakNoVar::check()
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
std::list<Scope>::const_iterator scope;
for (scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) {
// only check functions // only check functions
if (scope->type != Scope::eFunction) const std::size_t functions = symbolDatabase->functionScopes.size();
continue; for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
// goto the "}" that ends the executable scope.. // goto the "}" that ends the executable scope..
const Token *tok = scope->classEnd; const Token *tok = scope->classEnd;