@@ -369,6 +369,17 @@ class DenseMapBase : public DebugEpochBase {
369369protected:
370370 DenseMapBase () = default ;
371371
372+ struct ExactBucketCount {};
373+
374+ void initWithExactBucketCount (unsigned NewNumBuckets) {
375+ if (derived ().allocateBuckets (NewNumBuckets)) {
376+ initEmpty ();
377+ } else {
378+ setNumEntries (0 );
379+ setNumTombstones (0 );
380+ }
381+ }
382+
372383 void destroyAll () {
373384 // No need to iterate through the buckets if both KeyT and ValueT are
374385 // trivially destructible.
@@ -729,9 +740,8 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
729740 unsigned NumTombstones;
730741 unsigned NumBuckets;
731742
732- struct ExactBucketCount {};
733- explicit DenseMap (unsigned NumBuckets, ExactBucketCount) {
734- initWithExactBucketCount (NumBuckets);
743+ explicit DenseMap (unsigned NumBuckets, typename BaseT::ExactBucketCount) {
744+ this ->initWithExactBucketCount (NumBuckets);
735745 }
736746
737747public:
@@ -818,18 +828,9 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
818828 return true ;
819829 }
820830
821- void initWithExactBucketCount (unsigned NewNumBuckets) {
822- if (allocateBuckets (NewNumBuckets)) {
823- this ->BaseT ::initEmpty ();
824- } else {
825- NumEntries = 0 ;
826- NumTombstones = 0 ;
827- }
828- }
829-
830831 void init (unsigned InitNumEntries) {
831832 auto InitBuckets = BaseT::getMinBucketToReserveForEntries (InitNumEntries);
832- initWithExactBucketCount (InitBuckets);
833+ this -> initWithExactBucketCount (InitBuckets);
833834 }
834835
835836 // Put the zombie instance in a known good state after a move.
@@ -841,7 +842,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
841842
842843 void grow (unsigned AtLeast) {
843844 AtLeast = std::max<unsigned >(64 , NextPowerOf2 (AtLeast - 1 ));
844- DenseMap Tmp (AtLeast, ExactBucketCount{});
845+ DenseMap Tmp (AtLeast, typename BaseT:: ExactBucketCount{});
845846 Tmp.moveFrom (*this );
846847 swapImpl (Tmp);
847848 }
@@ -891,10 +892,8 @@ class SmallDenseMap
891892 // / a large bucket. This union will be discriminated by the 'Small' bit.
892893 AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
893894
894- struct ExactBucketCount {};
895- SmallDenseMap (unsigned NumBuckets, ExactBucketCount) {
896- allocateBuckets (NumBuckets);
897- this ->BaseT ::initEmpty ();
895+ SmallDenseMap (unsigned NumBuckets, typename BaseT::ExactBucketCount) {
896+ this ->initWithExactBucketCount (NumBuckets);
898897 }
899898
900899public:
@@ -1097,8 +1096,7 @@ class SmallDenseMap
10971096
10981097 void init (unsigned InitNumEntries) {
10991098 auto InitBuckets = BaseT::getMinBucketToReserveForEntries (InitNumEntries);
1100- allocateBuckets (InitBuckets);
1101- this ->BaseT ::initEmpty ();
1099+ this ->initWithExactBucketCount (InitBuckets);
11021100 }
11031101
11041102 // Put the zombie instance in a known good state after a move.
@@ -1112,7 +1110,7 @@ class SmallDenseMap
11121110 if (AtLeast > InlineBuckets)
11131111 AtLeast = std::max<unsigned >(64 , NextPowerOf2 (AtLeast - 1 ));
11141112
1115- SmallDenseMap Tmp (AtLeast, ExactBucketCount{});
1113+ SmallDenseMap Tmp (AtLeast, typename BaseT:: ExactBucketCount{});
11161114 Tmp.moveFrom (*this );
11171115
11181116 if (Tmp.Small ) {
0 commit comments