Skip to content

Commit 262bc46

Browse files
committed
Use StringRef::ends_with instead of rolling my own function per review comment.
1 parent 47670ce commit 262bc46

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ using namespace ento;
2525

2626
namespace {
2727

28-
bool stringEndsWith(const std::string &str, const std::string &suffix) {
29-
auto index = str.rfind(suffix);
30-
return index != std::string::npos && str.size() - suffix.size() == index;
31-
}
32-
3328
class UncountedCallArgsChecker
3429
: public Checker<check::ASTDecl<TranslationUnitDecl>> {
3530
BugType Bug{this,
@@ -217,17 +212,18 @@ class UncountedCallArgsChecker
217212
if (!NsDecl || !isa<NamespaceDecl>(NsDecl))
218213
return false;
219214

220-
auto methodName = safeGetName(Decl);
221-
auto clsName = safeGetName(ClassDecl);
222-
auto nsName = safeGetName(NsDecl);
215+
auto MethodName = safeGetName(Decl);
216+
auto ClsNameStr = safeGetName(ClassDecl);
217+
StringRef ClsName = ClsNameStr; // FIXME: Make safeGetName return StringRef.
218+
auto NamespaceName = safeGetName(NsDecl);
223219
// FIXME: These should be implemented via attributes.
224-
return nsName == "WTF" &&
225-
(methodName == "find" || methodName == "findIf" ||
226-
methodName == "reverseFind" || methodName == "reverseFindIf" ||
227-
methodName == "get" || methodName == "inlineGet" ||
228-
methodName == "contains" || methodName == "containsIf") &&
229-
(stringEndsWith(clsName, "Vector") ||
230-
stringEndsWith(clsName, "Set") || stringEndsWith(clsName, "Map"));
220+
return NamespaceName == "WTF" &&
221+
(MethodName == "find" || MethodName == "findIf" ||
222+
MethodName == "reverseFind" || MethodName == "reverseFindIf" ||
223+
MethodName == "get" || MethodName == "inlineGet" ||
224+
MethodName == "contains" || MethodName == "containsIf") &&
225+
(ClsName.ends_with("Vector") || ClsName.ends_with("Set") ||
226+
ClsName.ends_with("Map"));
231227
}
232228

233229
void reportBug(const Expr *CallArg, const ParmVarDecl *Param) const {

0 commit comments

Comments
 (0)