[PATCH] D90198: IR: Simplify two loops walking ConstantDataSequential, NFC

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 26 18:56:02 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGebb4ea1d53aa: IR: Simplify two loops walking ConstantDataSequential, NFC (authored by dexonsmith).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90198/new/

https://reviews.llvm.org/D90198

Files:
  llvm/lib/IR/Constants.cpp


Index: llvm/lib/IR/Constants.cpp
===================================================================
--- llvm/lib/IR/Constants.cpp
+++ llvm/lib/IR/Constants.cpp
@@ -2784,10 +2784,9 @@
   // of i8, or a 1-element array of i32.  They'll both end up in the same
   /// StringMap bucket, linked up by their Next pointers.  Walk the list.
   std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
-  for (ConstantDataSequential *Node = Entry->get(); Node;
-       Entry = &Node->Next, Node = Entry->get())
-    if (Node->getType() == Ty)
-      return Node;
+  for (; *Entry; Entry = &(*Entry)->Next)
+    if ((*Entry)->getType() == Ty)
+      return Entry->get();
 
   // Okay, we didn't get a hit.  Create a node of the right class, link it in,
   // and return it.
@@ -2825,14 +2824,16 @@
 
   // Otherwise, there are multiple entries linked off the bucket, unlink the
   // node we care about but keep the bucket around.
-  for (ConstantDataSequential *Node = Entry->get();;
-       Entry = &Node->Next, Node = Entry->get()) {
+  while (true) {
+    std::unique_ptr<ConstantDataSequential> &Node = *Entry;
     assert(Node && "Didn't find entry in its uniquing hash table!");
     // If we found our entry, unlink it from the list and we're done.
-    if (Node == this) {
-      *Entry = std::move(Node->Next);
+    if (Node.get() == this) {
+      Node = std::move(Node->Next);
       return;
     }
+
+    Entry = &Node->Next;
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90198.300856.patch
Type: text/x-patch
Size: 1446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201027/89b436f4/attachment.bin>


More information about the llvm-commits mailing list