Skip to content

Commit 847391e

Browse files
authored
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()`
1 parent 32d9610 commit 847391e

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

lib/cppcheck.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,21 +911,21 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
911911
ErrorMessage::FileLocation loc(e.token, &tokenizer.list);
912912
locationList.push_back(loc);
913913
} else {
914-
ErrorMessage::FileLocation loc(tokenizer.list.getSourceFilePath(), 0, 0);
915914
ErrorMessage::FileLocation loc2(filename, 0, 0);
916915
locationList.push_back(loc2);
917-
if (filename != tokenizer.list.getSourceFilePath())
916+
if (filename != tokenizer.list.getSourceFilePath()) {
917+
ErrorMessage::FileLocation loc(tokenizer.list.getSourceFilePath(), 0, 0);
918918
locationList.push_back(loc);
919+
}
919920
}
920-
ErrorMessage errmsg(locationList,
921+
ErrorMessage errmsg(std::move(locationList),
921922
tokenizer.list.getSourceFilePath(),
922923
Severity::error,
923924
e.errorMessage,
924925
e.id,
925926
Certainty::normal);
926927

927-
if (errmsg.severity == Severity::error || mSettings.severity.isEnabled(errmsg.severity))
928-
reportErr(errmsg);
928+
reportErr(errmsg);
929929
}
930930
}
931931

lib/templatesimplifier.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,10 @@ void TemplateSimplifier::expandTemplate(
21792179
continue;
21802180
}
21812181

2182+
// don't add instantiations in template definitions
2183+
if (!templates.empty())
2184+
continue;
2185+
21822186
std::string scope;
21832187
const Token *prev = tok3;
21842188
for (; Token::Match(prev->tokAt(-2), "%name% ::"); prev = prev->tokAt(-2)) {
@@ -2202,13 +2206,10 @@ void TemplateSimplifier::expandTemplate(
22022206
}
22032207
}
22042208

2205-
// don't add instantiations in template definitions
2206-
if (templates.empty()) {
2207-
if (copy)
2208-
newInstantiations.emplace_back(mTokenList.back(), scope);
2209-
else if (!inTemplateDefinition)
2210-
newInstantiations.emplace_back(tok3, scope);
2211-
}
2209+
if (copy)
2210+
newInstantiations.emplace_back(mTokenList.back(), scope);
2211+
else if (!inTemplateDefinition)
2212+
newInstantiations.emplace_back(tok3, scope);
22122213
}
22132214

22142215
// link() newly tokens manually

0 commit comments

Comments
 (0)