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
32 changes: 18 additions & 14 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ class DenseMapBase : public DebugEpochBase {
const KeyT EmptyKey = getEmptyKey();
if constexpr (std::is_trivially_destructible_v<ValueT>) {
// Use a simpler loop when values don't need destruction.
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P)
P->getFirst() = EmptyKey;
for (BucketT &B : buckets())
B.getFirst() = EmptyKey;
} else {
const KeyT TombstoneKey = getTombstoneKey();
unsigned NumEntries = getNumEntries();
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {
if (!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
P->getSecond().~ValueT();
for (BucketT &B : buckets()) {
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey)) {
if (!KeyInfoT::isEqual(B.getFirst(), TombstoneKey)) {
B.getSecond().~ValueT();
--NumEntries;
}
P->getFirst() = EmptyKey;
B.getFirst() = EmptyKey;
}
}
assert(NumEntries == 0 && "Node count imbalance!");
Expand Down Expand Up @@ -424,11 +424,11 @@ class DenseMapBase : public DebugEpochBase {
return;

const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey) &&
!KeyInfoT::isEqual(P->getFirst(), TombstoneKey))
P->getSecond().~ValueT();
P->getFirst().~KeyT();
for (BucketT &B : buckets()) {
if (!KeyInfoT::isEqual(B.getFirst(), EmptyKey) &&
!KeyInfoT::isEqual(B.getFirst(), TombstoneKey))
B.getSecond().~ValueT();
B.getFirst().~KeyT();
}
}

Expand All @@ -439,8 +439,8 @@ class DenseMapBase : public DebugEpochBase {
assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
"# initial buckets must be a power of two!");
const KeyT EmptyKey = getEmptyKey();
for (BucketT *B = getBuckets(), *E = getBucketsEnd(); B != E; ++B)
::new (&B->getFirst()) KeyT(EmptyKey);
for (BucketT &B : buckets())
::new (&B.getFirst()) KeyT(EmptyKey);
}

/// Returns the number of buckets to allocate to ensure that the DenseMap can
Expand Down Expand Up @@ -584,6 +584,10 @@ class DenseMapBase : public DebugEpochBase {
return getBuckets() + getNumBuckets();
}

iterator_range<BucketT *> buckets() {
return llvm::make_range(getBuckets(), getBucketsEnd());
}

void grow(unsigned AtLeast) { static_cast<DerivedT *>(this)->grow(AtLeast); }

void shrink_and_clear() { static_cast<DerivedT *>(this)->shrink_and_clear(); }
Expand Down