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
38 changes: 13 additions & 25 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1009,21 +1009,13 @@ class SmallDenseMap
void copyFrom(const SmallDenseMap &other) {
this->destroyAll();
deallocateBuckets();
Small = true;
if (other.getNumBuckets() > InlineBuckets) {
Small = false;
new (getLargeRep()) LargeRep(allocateBuckets(other.getNumBuckets()));
}
allocateBuckets(other.getNumBuckets());
this->BaseT::copyFrom(other);
}

void init(unsigned InitNumEntries) {
auto InitBuckets = BaseT::getMinBucketToReserveForEntries(InitNumEntries);
Small = true;
if (InitBuckets > InlineBuckets) {
Small = false;
new (getLargeRep()) LargeRep(allocateBuckets(InitBuckets));
}
allocateBuckets(InitBuckets);
this->BaseT::initEmpty();
}

Expand Down Expand Up @@ -1057,21 +1049,14 @@ class SmallDenseMap
// AtLeast == InlineBuckets can happen if there are many tombstones,
// and grow() is used to remove them. Usually we always switch to the
// large rep here.
if (AtLeast > InlineBuckets) {
Small = false;
new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
}
allocateBuckets(AtLeast);
this->moveFromOldBuckets(llvm::make_range(TmpBegin, TmpEnd));
return;
}

LargeRep OldRep = std::move(*getLargeRep());
getLargeRep()->~LargeRep();
if (AtLeast <= InlineBuckets) {
Small = true;
} else {
new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
}
allocateBuckets(AtLeast);

this->moveFromOldBuckets(OldRep.buckets());

Expand Down Expand Up @@ -1166,12 +1151,15 @@ class SmallDenseMap
getLargeRep()->~LargeRep();
}

LargeRep allocateBuckets(unsigned Num) {
assert(Num > InlineBuckets && "Must allocate more buckets than are inline");
LargeRep Rep = {static_cast<BucketT *>(allocate_buffer(
sizeof(BucketT) * Num, alignof(BucketT))),
Num};
return Rep;
void allocateBuckets(unsigned Num) {
if (Num <= InlineBuckets) {
Small = true;
} else {
Small = false;
BucketT *NewBuckets = static_cast<BucketT *>(
allocate_buffer(sizeof(BucketT) * Num, alignof(BucketT)));
new (getLargeRep()) LargeRep{NewBuckets, Num};
}
}
};

Expand Down
Loading