@@ -142,18 +142,18 @@ class DenseMapBase : public DebugEpochBase {
142
142
const KeyT EmptyKey = getEmptyKey ();
143
143
if constexpr (std::is_trivially_destructible_v<ValueT>) {
144
144
// Use a simpler loop when values don't need destruction.
145
- for (BucketT *P = getBuckets (), *E = getBucketsEnd (); P != E; ++P )
146
- P-> getFirst () = EmptyKey;
145
+ for (BucketT &B : buckets () )
146
+ B. getFirst () = EmptyKey;
147
147
} else {
148
148
const KeyT TombstoneKey = getTombstoneKey ();
149
149
unsigned NumEntries = getNumEntries ();
150
- for (BucketT *P = getBuckets (), *E = getBucketsEnd (); P != E; ++P ) {
151
- if (!KeyInfoT::isEqual (P-> getFirst (), EmptyKey)) {
152
- if (!KeyInfoT::isEqual (P-> getFirst (), TombstoneKey)) {
153
- P-> getSecond ().~ValueT ();
150
+ for (BucketT &B : buckets () ) {
151
+ if (!KeyInfoT::isEqual (B. getFirst (), EmptyKey)) {
152
+ if (!KeyInfoT::isEqual (B. getFirst (), TombstoneKey)) {
153
+ B. getSecond ().~ValueT ();
154
154
--NumEntries;
155
155
}
156
- P-> getFirst () = EmptyKey;
156
+ B. getFirst () = EmptyKey;
157
157
}
158
158
}
159
159
assert (NumEntries == 0 && " Node count imbalance!" );
@@ -424,11 +424,11 @@ class DenseMapBase : public DebugEpochBase {
424
424
return ;
425
425
426
426
const KeyT EmptyKey = getEmptyKey (), TombstoneKey = getTombstoneKey ();
427
- for (BucketT *P = getBuckets (), *E = getBucketsEnd (); P != E; ++P ) {
428
- if (!KeyInfoT::isEqual (P-> getFirst (), EmptyKey) &&
429
- !KeyInfoT::isEqual (P-> getFirst (), TombstoneKey))
430
- P-> getSecond ().~ValueT ();
431
- P-> getFirst ().~KeyT ();
427
+ for (BucketT &B : buckets () ) {
428
+ if (!KeyInfoT::isEqual (B. getFirst (), EmptyKey) &&
429
+ !KeyInfoT::isEqual (B. getFirst (), TombstoneKey))
430
+ B. getSecond ().~ValueT ();
431
+ B. getFirst ().~KeyT ();
432
432
}
433
433
}
434
434
@@ -439,8 +439,8 @@ class DenseMapBase : public DebugEpochBase {
439
439
assert ((getNumBuckets () & (getNumBuckets () - 1 )) == 0 &&
440
440
" # initial buckets must be a power of two!" );
441
441
const KeyT EmptyKey = getEmptyKey ();
442
- for (BucketT *B = getBuckets (), *E = getBucketsEnd (); B != E; ++B )
443
- ::new (&B-> getFirst ()) KeyT (EmptyKey);
442
+ for (BucketT &B : buckets () )
443
+ ::new (&B. getFirst ()) KeyT (EmptyKey);
444
444
}
445
445
446
446
// / Returns the number of buckets to allocate to ensure that the DenseMap can
@@ -584,6 +584,10 @@ class DenseMapBase : public DebugEpochBase {
584
584
return getBuckets () + getNumBuckets ();
585
585
}
586
586
587
+ iterator_range<BucketT *> buckets () {
588
+ return llvm::make_range (getBuckets (), getBucketsEnd ());
589
+ }
590
+
587
591
void grow (unsigned AtLeast) { static_cast <DerivedT *>(this )->grow (AtLeast); }
588
592
589
593
void shrink_and_clear () { static_cast <DerivedT *>(this )->shrink_and_clear (); }
0 commit comments