@@ -142,18 +142,18 @@ class DenseMapBase : public DebugEpochBase {
142142 const KeyT EmptyKey = getEmptyKey ();
143143 if constexpr (std::is_trivially_destructible_v<ValueT>) {
144144 // 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;
147147 } else {
148148 const KeyT TombstoneKey = getTombstoneKey ();
149149 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 ();
154154 --NumEntries;
155155 }
156- P-> getFirst () = EmptyKey;
156+ B. getFirst () = EmptyKey;
157157 }
158158 }
159159 assert (NumEntries == 0 && " Node count imbalance!" );
@@ -424,11 +424,11 @@ class DenseMapBase : public DebugEpochBase {
424424 return ;
425425
426426 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 ();
432432 }
433433 }
434434
@@ -439,8 +439,8 @@ class DenseMapBase : public DebugEpochBase {
439439 assert ((getNumBuckets () & (getNumBuckets () - 1 )) == 0 &&
440440 " # initial buckets must be a power of two!" );
441441 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);
444444 }
445445
446446 // / Returns the number of buckets to allocate to ensure that the DenseMap can
@@ -584,6 +584,10 @@ class DenseMapBase : public DebugEpochBase {
584584 return getBuckets () + getNumBuckets ();
585585 }
586586
587+ iterator_range<BucketT *> buckets () {
588+ return llvm::make_range (getBuckets (), getBucketsEnd ());
589+ }
590+
587591 void grow (unsigned AtLeast) { static_cast <DerivedT *>(this )->grow (AtLeast); }
588592
589593 void shrink_and_clear () { static_cast <DerivedT *>(this )->shrink_and_clear (); }
0 commit comments