]> granicus.if.org Git - clang/commitdiff
RetainCountChecker: Replace some loops with std:: algorithms.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 16 Aug 2013 21:57:14 +0000 (21:57 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 16 Aug 2013 21:57:14 +0000 (21:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188581 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

index 1a1fa4e2e9a0c8196d5983ccb8efb278001e7f6a..be2f2205d13b64b4f182eb5c7edf1f60751a894c 100644 (file)
@@ -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<ArgEffect>& V,
-                            ArgEffect X) {
-  for (SmallVectorImpl<ArgEffect>::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<IntegerLiteral>(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<StmtPoint>().getStmt();
       SVal X =