]> granicus.if.org Git - clang/commitdiff
Use remove_if to erase parts of a vector. Avoids O(n^2) worst cases.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 5 May 2013 12:39:28 +0000 (12:39 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 5 May 2013 12:39:28 +0000 (12:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181150 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/ASTUnit.cpp

index 8fe4baa5e301eeb5c98a13203f07a7e9c04faedd..8bd5172454ca2bceb460ebe578d64bb24c72dce9 100644 (file)
@@ -1037,16 +1037,17 @@ public:
 
 }
 
-static void checkAndRemoveNonDriverDiags(SmallVectorImpl<StoredDiagnostic> &
-                                                            StoredDiagnostics) {
+static bool isNonDriverDiag(const StoredDiagnostic &StoredDiag) {
+  return StoredDiag.getLocation().isValid();
+}
+
+static void
+checkAndRemoveNonDriverDiags(SmallVectorImpl<StoredDiagnostic> &StoredDiags) {
   // Get rid of stored diagnostics except the ones from the driver which do not
   // have a source location.
-  for (unsigned I = 0; I < StoredDiagnostics.size(); ++I) {
-    if (StoredDiagnostics[I].getLocation().isValid()) {
-      StoredDiagnostics.erase(StoredDiagnostics.begin()+I);
-      --I;
-    }
-  }
+  StoredDiags.erase(
+      std::remove_if(StoredDiags.begin(), StoredDiags.end(), isNonDriverDiag),
+      StoredDiags.end());
 }
 
 static void checkAndSanitizeDiags(SmallVectorImpl<StoredDiagnostic> &