Symbol Database: Don't use it when it is not needed

This commit is contained in:
Daniel Marjamäki 2010-08-07 12:41:11 +02:00
parent 9e7b087832
commit 54121a74ff
2 changed files with 38 additions and 2 deletions

View File

@ -41,8 +41,20 @@ CheckClass instance;
//---------------------------------------------------------------------------
CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger)
: Check(tokenizer, settings, errorLogger),
hasSymbolDatabase(false)
{
}
void CheckClass::createSymbolDatabase()
{
// Multiple calls => bail out
if (hasSymbolDatabase)
return;
hasSymbolDatabase = true;
// find all namespaces (class,struct and namespace)
SpaceInfo *info = 0;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -815,6 +827,8 @@ void CheckClass::constructors()
if (!_settings->_checkCodingStyle)
return;
createSymbolDatabase();
std::multimap<std::string, SpaceInfo *>::iterator i;
for (i = spaceInfoMMap.begin(); i != spaceInfoMMap.end(); ++i)
@ -1161,6 +1175,8 @@ void CheckClass::operatorEq()
if (!_settings->_checkCodingStyle)
return;
createSymbolDatabase();
std::multimap<std::string, SpaceInfo *>::const_iterator i;
for (i = spaceInfoMMap.begin(); i != spaceInfoMMap.end(); ++i)
@ -1188,6 +1204,8 @@ void CheckClass::operatorEqRetRefThis()
if (!_settings->_checkCodingStyle)
return;
createSymbolDatabase();
std::multimap<std::string, SpaceInfo *>::const_iterator i;
for (i = spaceInfoMMap.begin(); i != spaceInfoMMap.end(); ++i)
@ -1834,6 +1852,8 @@ void CheckClass::checkConst()
if (!_settings->_checkCodingStyle)
return;
createSymbolDatabase();
std::multimap<std::string, SpaceInfo *>::iterator it;
for (it = spaceInfoMMap.begin(); it != spaceInfoMMap.end(); ++it)

View File

@ -36,7 +36,7 @@ class CheckClass : public Check
{
public:
/** @brief This constructor is used when registering the CheckClass */
CheckClass() : Check()
CheckClass() : Check(), hasSymbolDatabase(false)
{ }
/** @brief This constructor is used when running checks. */
@ -112,6 +112,22 @@ public:
enum AccessControl { Public, Protected, Private };
private:
/**
* @brief Create symbol database. For performance reasons, only call
* it if it's needed.
*/
void createSymbolDatabase();
/**
* @brief Prevent creating symbol database more than once.
*
* Initialize this flag to false in the constructors. If this flag
* is true the createSymbolDatabase should just bail out. If it is
* false the createSymbolDatabase will set it to true and create
* the symbol database.
*/
bool hasSymbolDatabase;
/** @brief Information about a member variable. Used when checking for uninitialized variables */
class Var
{