LiveRange: Replace a creative vector erase loop with std::remove_if.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 28 Feb 2015 20:14:27 +0000 (20:14 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 28 Feb 2015 20:14:27 +0000 (20:14 +0000)
I didn't see this so far because it scans backwards, but that doesn't
make it any less quadratic. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230863 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/LiveInterval.cpp

index fd7516dfd4713813b1d7f5190633f7ec43b73a5d..d60b0b1a50409ff69f774b16376426131b568a41 100644 (file)
@@ -567,13 +567,9 @@ void LiveRange::removeSegment(SlotIndex Start, SlotIndex End,
 /// Also remove the value# from value# list.
 void LiveRange::removeValNo(VNInfo *ValNo) {
   if (empty()) return;
-  iterator I = end();
-  iterator E = begin();
-  do {
-    --I;
-    if (I->valno == ValNo)
-      segments.erase(I);
-  } while (I != E);
+  segments.erase(std::remove_if(begin(), end(), [ValNo](const Segment &S) {
+    return S.valno == ValNo;
+  }), end());
   // Now that ValNo is dead, remove it.
   markValNoForDeletion(ValNo);
 }