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
24 changes: 16 additions & 8 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ class DenseMapBase : public DebugEpochBase {
return getBuckets();
}

void swap(DerivedT &RHS) {
this->incrementEpoch();
RHS.incrementEpoch();
Comment on lines +363 to +365
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the epoch number something we could test for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in a somewhat limited manner. The epoch number is hiding in LLVM_ENABLE_ABI_BREAKING_CHECKS, so we could test it when the macro is on.

If turn it on ourselves in a unit test, then we might run into issues with other source files -- with two different definitions of DenseMap in a unit test executable.

derived().swapImpl(RHS);
}

protected:
DenseMapBase() = default;

Expand Down Expand Up @@ -736,7 +742,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,

DenseMap(DenseMap &&other) : BaseT() {
init(0);
swap(other);
this->swap(other);
}

template <typename InputIt> DenseMap(const InputIt &I, const InputIt &E) {
Expand All @@ -756,15 +762,15 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
deallocateBuckets();
}

void swap(DenseMap &RHS) {
this->incrementEpoch();
RHS.incrementEpoch();
private:
void swapImpl(DenseMap &RHS) {
std::swap(Buckets, RHS.Buckets);
std::swap(NumEntries, RHS.NumEntries);
std::swap(NumTombstones, RHS.NumTombstones);
std::swap(NumBuckets, RHS.NumBuckets);
}

public:
DenseMap &operator=(const DenseMap &other) {
if (&other != this)
this->copyFrom(other);
Expand All @@ -775,7 +781,7 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
this->destroyAll();
deallocateBuckets();
init(0);
swap(other);
this->swap(other);
return *this;
}

Expand Down Expand Up @@ -895,7 +901,7 @@ class SmallDenseMap

SmallDenseMap(SmallDenseMap &&other) : BaseT() {
init(0);
swap(other);
this->swap(other);
}

template <typename InputIt>
Expand All @@ -916,7 +922,8 @@ class SmallDenseMap
deallocateBuckets();
}

void swap(SmallDenseMap &RHS) {
private:
void swapImpl(SmallDenseMap &RHS) {
unsigned TmpNumEntries = RHS.NumEntries;
RHS.NumEntries = NumEntries;
NumEntries = TmpNumEntries;
Expand Down Expand Up @@ -987,6 +994,7 @@ class SmallDenseMap
new (SmallSide.getLargeRep()) LargeRep(std::move(TmpRep));
}

public:
SmallDenseMap &operator=(const SmallDenseMap &other) {
if (&other != this)
this->copyFrom(other);
Expand All @@ -997,7 +1005,7 @@ class SmallDenseMap
this->destroyAll();
deallocateBuckets();
init(0);
swap(other);
this->swap(other);
return *this;
}

Expand Down
Loading