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
23 changes: 17 additions & 6 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ class DenseMapBase : public DebugEpochBase {
return llvm::make_range(getBuckets(), getBucketsEnd());
}

void grow(unsigned AtLeast) { derived().grow(AtLeast); }
void grow(unsigned MinNumBuckets) {
unsigned NumBuckets = DerivedT::roundUpNumBuckets(MinNumBuckets);
derived().grow(NumBuckets);
}

template <typename LookupKeyT>
BucketT *findBucketForInsertion(const LookupKeyT &Lookup,
Expand Down Expand Up @@ -840,8 +843,12 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
NumBuckets = 0;
}

static unsigned roundUpNumBuckets(unsigned MinNumBuckets) {
return std::max(64u,
static_cast<unsigned>(NextPowerOf2(MinNumBuckets - 1)));
}

void grow(unsigned AtLeast) {
AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));
DenseMap Tmp(AtLeast, typename BaseT::ExactBucketCount{});
Tmp.moveFrom(*this);
swapImpl(Tmp);
Expand Down Expand Up @@ -1106,11 +1113,15 @@ class SmallDenseMap
new (getLargeRep()) LargeRep{nullptr, 0};
}

void grow(unsigned AtLeast) {
if (AtLeast > InlineBuckets)
AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast - 1));
static unsigned roundUpNumBuckets(unsigned MinNumBuckets) {
if (MinNumBuckets <= InlineBuckets)
return MinNumBuckets;
return std::max(64u,
static_cast<unsigned>(NextPowerOf2(MinNumBuckets - 1)));
}

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

if (Tmp.Small) {
Expand Down
Loading