From dbf2c44a8163bc885070e8f425a203752d50ca7c Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 2 Apr 2014 19:01:37 +0200 Subject: [PATCH] Simplified check registration: - Use sorted insert instead of calling std::list::sort() on each insertion - Removed DJGPP/__sun hack in check.h (should be obsolete by our compiler requirements for C++11 --- lib/check.h | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/check.h b/lib/check.h index d8b7fd003..4c3fc7bcd 100644 --- a/lib/check.h +++ b/lib/check.h @@ -41,7 +41,16 @@ class CPPCHECKLIB Check { public: /** This constructor is used when registering the CheckClass */ - explicit Check(const std::string &aname); + explicit Check(const std::string &aname) + : _tokenizer(0), _settings(0), _errorLogger(0), _name(aname) { + for (std::list::iterator i = instances().begin(); i != instances(). end(); ++i) { + if ((*i)->name() > aname) { + instances().insert(i, this); + return; + } + } + instances().push_back(this); + } /** This constructor is used when running checks. */ Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) @@ -49,9 +58,8 @@ public: } virtual ~Check() { -#if !defined(DJGPP) && !defined(__sun) - instances().remove(this); -#endif + if (!_tokenizer) + instances().remove(this); } /** List of registered check classes. This is used by Cppcheck to run checks and generate documentation */ @@ -141,22 +149,6 @@ private: Check(const Check &); }; -namespace std { - /** compare the names of Check classes, used when sorting the Check descendants */ - template <> struct less { - bool operator()(const Check *p1, const Check *p2) const { - return (p1->name() < p2->name()); - } - }; -} - -inline Check::Check(const std::string &aname) - : _tokenizer(0), _settings(0), _errorLogger(0), _name(aname) -{ - instances().push_back(this); - instances().sort(std::less()); -} - /// @} //--------------------------------------------------------------------------- #endif // checkH