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)
This commit is contained in:
PKEuS 2014-04-02 18:04:20 +02:00
parent d4765bccc3
commit d9358de8b4
5 changed files with 17 additions and 18 deletions

View File

@ -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<typename T, typename U>
void reportError(const Token *tok, const Severity::SeverityType severity, const T id, const U msg, bool inconclusive = false) {
std::list<const Token *> callstack(1, tok);
reportError(callstack, severity, id, msg, inconclusive);
}
/** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string& msg, bool inconclusive = false) {
template<typename T, typename U>
void reportError(const std::list<const Token *> &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);

View File

@ -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)
{

View File

@ -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<typename T>
bool isEnabled(T&& str) const {
return bool(_enabled.find(str) != _enabled.end());
}
/**
* @brief Enable extra checks by id. See isEnabled()

View File

@ -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);

View File

@ -69,7 +69,13 @@ public:
explicit Token(Token **tokensBack);
~Token();
void str(const std::string &s);
template<typename T>
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<typename T>
void originalName(T&& name) {
_originalName = name;
}