From d9358de8b4779191f4eacfd551e23acf899c43d5 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 2 Apr 2014 18:04:20 +0200 Subject: [PATCH] Refactorization: Use templates and rValue references -> Performance gain of up to 15% on entire checking time (depends on setup; Result was checked with VS12 (x64), matchcompiled version, ran on tinyxml and cppcheck itself) --- lib/check.h | 6 ++++-- lib/settings.cpp | 5 ----- lib/settings.h | 5 ++++- lib/token.cpp | 8 -------- lib/token.h | 11 +++++++++-- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/check.h b/lib/check.h index cabb43cd1..d8b7fd003 100644 --- a/lib/check.h +++ b/lib/check.h @@ -117,13 +117,15 @@ protected: ErrorLogger * const _errorLogger; /** report an error */ - void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, bool inconclusive = false) { + template + void reportError(const Token *tok, const Severity::SeverityType severity, const T id, const U msg, bool inconclusive = false) { std::list callstack(1, tok); reportError(callstack, severity, id, msg, inconclusive); } /** report an error */ - void reportError(const std::list &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg, bool inconclusive = false) { + template + void reportError(const std::list &callstack, Severity::SeverityType severity, const T id, const U msg, bool inconclusive = false) { ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer?&_tokenizer->list:0, severity, id, msg, inconclusive); if (_errorLogger) _errorLogger->reportErr(errmsg); diff --git a/lib/settings.cpp b/lib/settings.cpp index a383b786d..b74d0793d 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -112,11 +112,6 @@ std::string Settings::addEnabled(const std::string &str) return std::string(""); } -bool Settings::isEnabled(const std::string &str) const -{ - return bool(_enabled.find(str) != _enabled.end()); -} - bool Settings::append(const std::string &filename) { diff --git a/lib/settings.h b/lib/settings.h index 16c03679d..a520ff054 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -149,7 +149,10 @@ public: * @param str id for the extra check, e.g. "style" * @return true if the check is enabled. */ - bool isEnabled(const std::string &str) const; + template + bool isEnabled(T&& str) const { + return bool(_enabled.find(str) != _enabled.end()); + } /** * @brief Enable extra checks by id. See isEnabled() diff --git a/lib/token.cpp b/lib/token.cpp index 149ae0e56..d978facc0 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -152,14 +152,6 @@ bool Token::isUpperCaseName() const return true; } -void Token::str(const std::string &s) -{ - _str = s; - _varId = 0; - - update_property_info(); -} - void Token::concatStr(std::string const& b) { _str.erase(_str.length() - 1); diff --git a/lib/token.h b/lib/token.h index 6a058725b..01b126eac 100644 --- a/lib/token.h +++ b/lib/token.h @@ -69,7 +69,13 @@ public: explicit Token(Token **tokensBack); ~Token(); - void str(const std::string &s); + template + void str(T&& s) { + _str = s; + _varId = 0; + + update_property_info(); + } /** * Concatenate two (quoted) strings. Automatically cuts of the last/first character. @@ -593,7 +599,8 @@ public: /** * Sets the original name. */ - void originalName(const std::string & name) { + template + void originalName(T&& name) { _originalName = name; }