Skip to content

Commit 12ef487

Browse files
[ADT] Use a range-based for loop in DenseMap.h (NFC) (#152084)
This patch introduces inlineBuckets to convert a loop into a range-based for loop.
1 parent 1d594fd commit 12ef487

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

llvm/include/llvm/ADT/DenseMap.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,17 +1109,17 @@ class SmallDenseMap
11091109
// temporary storage. Have the loop move the TmpEnd forward as it goes.
11101110
const KeyT EmptyKey = this->getEmptyKey();
11111111
const KeyT TombstoneKey = this->getTombstoneKey();
1112-
for (BucketT *P = getBuckets(), *E = P + InlineBuckets; P != E; ++P) {
1113-
if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey) &&
1114-
!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
1112+
for (BucketT &B : inlineBuckets()) {
1113+
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey) &&
1114+
!KeyInfoT::isEqual(B.getFirst(), TombstoneKey)) {
11151115
assert(size_t(TmpEnd - TmpBegin) < InlineBuckets &&
11161116
"Too many inline buckets!");
1117-
::new (&TmpEnd->getFirst()) KeyT(std::move(P->getFirst()));
1118-
::new (&TmpEnd->getSecond()) ValueT(std::move(P->getSecond()));
1117+
::new (&TmpEnd->getFirst()) KeyT(std::move(B.getFirst()));
1118+
::new (&TmpEnd->getSecond()) ValueT(std::move(B.getSecond()));
11191119
++TmpEnd;
1120-
P->getSecond().~ValueT();
1120+
B.getSecond().~ValueT();
11211121
}
1122-
P->getFirst().~KeyT();
1122+
B.getFirst().~KeyT();
11231123
}
11241124

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

1223+
iterator_range<BucketT *> inlineBuckets() {
1224+
BucketT *Begin = getInlineBuckets();
1225+
return llvm::make_range(Begin, Begin + InlineBuckets);
1226+
}
1227+
12231228
void deallocateBuckets() {
12241229
if (Small)
12251230
return;

0 commit comments

Comments
 (0)