some minor optimizations (#4449)
* cppcheck.cpp: reduced scope of a variable * cppcheck.cpp: removed unnecessary severity checks * cppcheck.cpp: avoid unnecessary copy * templatesimplifier.cpp: perform early exit in loop in `expandTemplate()`
This commit is contained in:
parent
32d96104d6
commit
847391ea2d
|
@ -911,21 +911,21 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
|
|||
ErrorMessage::FileLocation loc(e.token, &tokenizer.list);
|
||||
locationList.push_back(loc);
|
||||
} else {
|
||||
ErrorMessage::FileLocation loc(tokenizer.list.getSourceFilePath(), 0, 0);
|
||||
ErrorMessage::FileLocation loc2(filename, 0, 0);
|
||||
locationList.push_back(loc2);
|
||||
if (filename != tokenizer.list.getSourceFilePath())
|
||||
if (filename != tokenizer.list.getSourceFilePath()) {
|
||||
ErrorMessage::FileLocation loc(tokenizer.list.getSourceFilePath(), 0, 0);
|
||||
locationList.push_back(loc);
|
||||
}
|
||||
}
|
||||
ErrorMessage errmsg(locationList,
|
||||
ErrorMessage errmsg(std::move(locationList),
|
||||
tokenizer.list.getSourceFilePath(),
|
||||
Severity::error,
|
||||
e.errorMessage,
|
||||
e.id,
|
||||
Certainty::normal);
|
||||
|
||||
if (errmsg.severity == Severity::error || mSettings.severity.isEnabled(errmsg.severity))
|
||||
reportErr(errmsg);
|
||||
reportErr(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2179,6 +2179,10 @@ void TemplateSimplifier::expandTemplate(
|
|||
continue;
|
||||
}
|
||||
|
||||
// don't add instantiations in template definitions
|
||||
if (!templates.empty())
|
||||
continue;
|
||||
|
||||
std::string scope;
|
||||
const Token *prev = tok3;
|
||||
for (; Token::Match(prev->tokAt(-2), "%name% ::"); prev = prev->tokAt(-2)) {
|
||||
|
@ -2202,13 +2206,10 @@ void TemplateSimplifier::expandTemplate(
|
|||
}
|
||||
}
|
||||
|
||||
// don't add instantiations in template definitions
|
||||
if (templates.empty()) {
|
||||
if (copy)
|
||||
newInstantiations.emplace_back(mTokenList.back(), scope);
|
||||
else if (!inTemplateDefinition)
|
||||
newInstantiations.emplace_back(tok3, scope);
|
||||
}
|
||||
if (copy)
|
||||
newInstantiations.emplace_back(mTokenList.back(), scope);
|
||||
else if (!inTemplateDefinition)
|
||||
newInstantiations.emplace_back(tok3, scope);
|
||||
}
|
||||
|
||||
// link() newly tokens manually
|
||||
|
|
Loading…
Reference in New Issue