r181150 - Use remove_if to erase parts of a vector. Avoids O(n^2) worst cases.
Benjamin Kramer
benny.kra at googlemail.com
Sun May 5 05:39:28 PDT 2013
Author: d0k
Date: Sun May 5 07:39:28 2013
New Revision: 181150
URL: http://llvm.org/viewvc/llvm-project?rev=181150&view=rev
Log:
Use remove_if to erase parts of a vector. Avoids O(n^2) worst cases.
Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=181150&r1=181149&r2=181150&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sun May 5 07:39:28 2013
@@ -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> &
More information about the cfe-commits
mailing list