IR: Use remove_if for Instruction::dropUnknownMetadata()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 24 Apr 2015 20:23:44 +0000 (20:23 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Fri, 24 Apr 2015 20:23:44 +0000 (20:23 +0000)
Technically the operations are different -- the old logic moved items
from the back into the opened-up slots, instead of the usual
`remove_if()` logic of a slow and a fast iterator -- but unless a
profile tells us otherwise I prefer the simpler logic here.  Regardless,
there shouldn't be an observable function change.

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

lib/IR/Metadata.cpp

index 6e54fa918b3c86ddb05e17667b7334622b94eba6..752c4b276b710cb6f191b21204e3a116857a3e1b 100644 (file)
@@ -1007,22 +1007,14 @@ void Instruction::dropUnknownMetadata(ArrayRef<unsigned> KnownIDs) {
   }
 
   auto &Info = InstructionMetadata[this];
-  unsigned I;
-  unsigned E;
-  // Walk the array and drop any metadata we don't know.
-  for (I = 0, E = Info.size(); I != E;) {
-    if (KnownSet.count(Info[I].first)) {
-      ++I;
-      continue;
-    }
-
-    Info[I] = std::move(Info.back());
-    Info.pop_back();
-    --E;
-  }
-  assert(E == Info.size());
-
-  if (E == 0) {
+  Info.erase(std::remove_if(
+                 Info.begin(), Info.end(),
+                 [&KnownSet](const std::pair<unsigned, TrackingMDNodeRef> &I) {
+                   return !KnownSet.count(I.first);
+                 }),
+             Info.end());
+
+  if (Info.empty()) {
     // Drop our entry at the store.
     InstructionMetadata.erase(this);
     setHasMetadataHashEntry(false);