Skip to content
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
40 changes: 19 additions & 21 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ class DenseMapBase : public DebugEpochBase {
protected:
DenseMapBase() = default;

struct ExactBucketCount {};

void initWithExactBucketCount(unsigned NewNumBuckets) {
if (derived().allocateBuckets(NewNumBuckets)) {
initEmpty();
} else {
setNumEntries(0);
setNumTombstones(0);
}
}

void destroyAll() {
// No need to iterate through the buckets if both KeyT and ValueT are
// trivially destructible.
Expand Down Expand Up @@ -729,9 +740,8 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
unsigned NumTombstones;
unsigned NumBuckets;

struct ExactBucketCount {};
explicit DenseMap(unsigned NumBuckets, ExactBucketCount) {
initWithExactBucketCount(NumBuckets);
explicit DenseMap(unsigned NumBuckets, typename BaseT::ExactBucketCount) {
this->initWithExactBucketCount(NumBuckets);
}

public:
Expand Down Expand Up @@ -818,18 +828,9 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
return true;
}

void initWithExactBucketCount(unsigned NewNumBuckets) {
if (allocateBuckets(NewNumBuckets)) {
this->BaseT::initEmpty();
} else {
NumEntries = 0;
NumTombstones = 0;
}
}

void init(unsigned InitNumEntries) {
auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
initWithExactBucketCount(InitBuckets);
this->initWithExactBucketCount(InitBuckets);
}

// Put the zombie instance in a known good state after a move.
Expand All @@ -841,7 +842,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,

void grow(unsigned AtLeast) {
AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));
DenseMap Tmp(AtLeast, ExactBucketCount{});
DenseMap Tmp(AtLeast, typename BaseT::ExactBucketCount{});
Tmp.moveFrom(*this);
swapImpl(Tmp);
}
Expand Down Expand Up @@ -891,10 +892,8 @@ class SmallDenseMap
/// a large bucket. This union will be discriminated by the 'Small' bit.
AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;

struct ExactBucketCount {};
SmallDenseMap(unsigned NumBuckets, ExactBucketCount) {
allocateBuckets(NumBuckets);
this->BaseT::initEmpty();
SmallDenseMap(unsigned NumBuckets, typename BaseT::ExactBucketCount) {
this->initWithExactBucketCount(NumBuckets);
}

public:
Expand Down Expand Up @@ -1097,8 +1096,7 @@ class SmallDenseMap

void init(unsigned InitNumEntries) {
auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
allocateBuckets(InitBuckets);
this->BaseT::initEmpty();
this->initWithExactBucketCount(InitBuckets);
}

// Put the zombie instance in a known good state after a move.
Expand All @@ -1112,7 +1110,7 @@ class SmallDenseMap
if (AtLeast > InlineBuckets)
AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));

SmallDenseMap Tmp(AtLeast, ExactBucketCount{});
SmallDenseMap Tmp(AtLeast, typename BaseT::ExactBucketCount{});
Tmp.moveFrom(*this);

if (Tmp.Small) {
Expand Down
Loading