[llvm] r235767 - IR: Use remove_if for Instruction::dropUnknownMetadata()

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Apr 24 13:23:44 PDT 2015


Author: dexonsmith
Date: Fri Apr 24 15:23:44 2015
New Revision: 235767

URL: http://llvm.org/viewvc/llvm-project?rev=235767&view=rev
Log:
IR: Use remove_if for Instruction::dropUnknownMetadata()

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.

Modified:
    llvm/trunk/lib/IR/Metadata.cpp

Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=235767&r1=235766&r2=235767&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Fri Apr 24 15:23:44 2015
@@ -1007,22 +1007,14 @@ void Instruction::dropUnknownMetadata(Ar
   }
 
   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.erase(std::remove_if(
+                 Info.begin(), Info.end(),
+                 [&KnownSet](const std::pair<unsigned, TrackingMDNodeRef> &I) {
+                   return !KnownSet.count(I.first);
+                 }),
+             Info.end());
 
-    Info[I] = std::move(Info.back());
-    Info.pop_back();
-    --E;
-  }
-  assert(E == Info.size());
-
-  if (E == 0) {
+  if (Info.empty()) {
     // Drop our entry at the store.
     InstructionMetadata.erase(this);
     setHasMetadataHashEntry(false);





More information about the llvm-commits mailing list