From 54121a74ff393815db273b938cbff323fee3b474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 7 Aug 2010 12:41:11 +0200 Subject: [PATCH] Symbol Database: Don't use it when it is not needed --- lib/checkclass.cpp | 22 +++++++++++++++++++++- lib/checkclass.h | 18 +++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index a54cee103..63b761d2f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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::iterator i; for (i = spaceInfoMMap.begin(); i != spaceInfoMMap.end(); ++i) @@ -1161,6 +1175,8 @@ void CheckClass::operatorEq() if (!_settings->_checkCodingStyle) return; + createSymbolDatabase(); + std::multimap::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::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::iterator it; for (it = spaceInfoMMap.begin(); it != spaceInfoMMap.end(); ++it) diff --git a/lib/checkclass.h b/lib/checkclass.h index eec75691d..6bc4ddc0b 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -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 {