Skip to content

[ADT] Use a range-based for loop in DenseMap.h (NFC) #152084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1109,17 +1109,17 @@ class SmallDenseMap
// temporary storage. Have the loop move the TmpEnd forward as it goes.
const KeyT EmptyKey = this->getEmptyKey();
const KeyT TombstoneKey = this->getTombstoneKey();
for (BucketT *P = getBuckets(), *E = P + InlineBuckets; P != E; ++P) {
if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey) &&
!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
for (BucketT &B : inlineBuckets()) {
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey) &&
!KeyInfoT::isEqual(B.getFirst(), TombstoneKey)) {
assert(size_t(TmpEnd - TmpBegin) < InlineBuckets &&
"Too many inline buckets!");
::new (&TmpEnd->getFirst()) KeyT(std::move(P->getFirst()));
::new (&TmpEnd->getSecond()) ValueT(std::move(P->getSecond()));
::new (&TmpEnd->getFirst()) KeyT(std::move(B.getFirst()));
::new (&TmpEnd->getSecond()) ValueT(std::move(B.getSecond()));
++TmpEnd;
P->getSecond().~ValueT();
B.getSecond().~ValueT();
}
P->getFirst().~KeyT();
B.getFirst().~KeyT();
}

// AtLeast == InlineBuckets can happen if there are many tombstones,
Expand Down Expand Up @@ -1220,6 +1220,11 @@ class SmallDenseMap
return Small ? InlineBuckets : getLargeRep()->NumBuckets;
}

iterator_range<BucketT *> inlineBuckets() {
BucketT *Begin = getInlineBuckets();
return llvm::make_range(Begin, Begin + InlineBuckets);
}

void deallocateBuckets() {
if (Small)
return;
Expand Down