[PATCH] [clang-tidy] Checker for inefficient use of algorithms on associative containers
Alexander Kornienko
alexfh at google.com
Tue Feb 3 02:38:33 PST 2015
================
Comment at: clang-tidy/misc/InefficientAlgorithmCheck.cpp:24
@@ +23,3 @@
+ const auto ContainerMatcher = classTemplateSpecializationDecl(
+ matchesName("std::(set|multiset|map|multimap)"));
+ const auto Matcher =
----------------
What about unordered_(multi)?(set|map)?
================
Comment at: clang-tidy/misc/InefficientAlgorithmCheck.cpp:37
@@ +36,3 @@
+ callee(methodDecl(hasName("end"))),
+ on(anyOf(hasType(ContainerMatcher),
+ hasType(pointsTo(ContainerMatcher)))))))),
----------------
Maybe something along the lines of on(equalsBoundNode("IneffContObj"))?
================
Comment at: clang-tidy/misc/InefficientAlgorithmCheck.cpp:68
@@ +67,3 @@
+ if (AlgCmp != ContainerCmp) {
+ diag(Arg->getLocStart(), "incompatible compare with the container.");
+ return;
----------------
I'm not a native speaker, but the message seems a bit unclear. How about "different comparers used in the algorithm and the container"?
Also, please remove the trailing period.
================
Comment at: clang-tidy/misc/InefficientAlgorithmCheck.cpp:82
@@ +81,3 @@
+ if (!AlgCall->getLocStart().isMacroID()) {
+ std::string ReplacementText = Lexer::getSourceText(
+ CharSourceRange::getTokenRange(IneffContObj->getSourceRange()),
----------------
A Twine can be used here instead.
================
Comment at: clang-tidy/misc/InefficientAlgorithmCheck.cpp:96
@@ +95,3 @@
+ diag(AlgCall->getLocStart(),
+ "this STL algorithm call should be replaced with a container method.")
+ << Hint;
----------------
Please remove the trailing period.
http://reviews.llvm.org/D7246
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list