From: Benjamin Kramer Date: Fri, 16 Aug 2013 21:57:14 +0000 (+0000) Subject: RetainCountChecker: Replace some loops with std:: algorithms. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1da6b24327b2c311f3e4689d45427c11fc73398;p=clang RetainCountChecker: Replace some loops with std:: algorithms. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188581 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 1a1fa4e2e9..be2f2205d1 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -321,11 +321,7 @@ public: /// Return the number of argument effects. This is O(n) in the number /// of arguments. unsigned getNumArgs() const { - unsigned N = 0; - for (ArgEffects::iterator I = Args.begin(), E = Args.end(); I != E; ++I) { - ++N; - }; - return N; + return std::distance(Args.begin(), Args.end()); } void addArg(ArgEffects::Factory &af, unsigned idx, ArgEffect e) { @@ -1754,16 +1750,6 @@ void CFRefReport::addGCModeDescription(const LangOptions &LOpts, addExtraText(GCModeDescription); } -// FIXME: This should be a method on SmallVector. -static inline bool contains(const SmallVectorImpl& V, - ArgEffect X) { - for (SmallVectorImpl::const_iterator I=V.begin(), E=V.end(); - I!=E; ++I) - if (*I == X) return true; - - return false; -} - static bool isNumericLiteralExpression(const Expr *E) { // FIXME: This set of cases was copied from SemaExprObjC. return isa(E) || @@ -1925,7 +1911,8 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, RefVal PrevV = *PrevT; // Specially handle -dealloc. - if (!GCEnabled && contains(AEffects, Dealloc)) { + if (!GCEnabled && std::find(AEffects.begin(), AEffects.end(), Dealloc) != + AEffects.end()) { // Determine if the object's reference count was pushed to zero. assert(!(PrevV == CurrV) && "The typestate *must* have changed."); // We may not have transitioned to 'release' if we hit an error. @@ -1938,7 +1925,8 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, } // Specially handle CFMakeCollectable and friends. - if (contains(AEffects, MakeCollectable)) { + if (std::find(AEffects.begin(), AEffects.end(), MakeCollectable) != + AEffects.end()) { // Get the name of the function. const Stmt *S = N->getLocation().castAs().getStmt(); SVal X =