aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-26 19:03:23 -0400
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2020-10-26 21:55:48 -0400
commitebb4ea1d53aaccd91138bfd6afdc9b39fd784d83 (patch)
treec90504e29275c60399136acce8df75302ebc145a /llvm/lib/IR/Constants.cpp
parent470d2d1d28c6ffa45cc40ad8c35cb79851741131 (diff)
downloadllvm-ebb4ea1d53aaccd91138bfd6afdc9b39fd784d83.zip
llvm-ebb4ea1d53aaccd91138bfd6afdc9b39fd784d83.tar.gz
llvm-ebb4ea1d53aaccd91138bfd6afdc9b39fd784d83.tar.bz2
IR: Simplify two loops walking ConstantDataSequential, NFC
Follow-up to b2b7cf39d596b1528cd64015575b3f5d1461c011. Differential Revision: https://reviews.llvm.org/D90198
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 0436a6e..3d8555b 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2784,10 +2784,9 @@ Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {
// 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 @@ void ConstantDataSequential::destroyConstantImpl() {
// 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;
}
}