mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
Fix SmallDenseMap assignment operator.
Self assignment would lead to buckets of garbage, causing quadratic probing to hang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214790 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -305,6 +305,7 @@ protected:
|
|||||||
|
|
||||||
template <typename OtherBaseT>
|
template <typename OtherBaseT>
|
||||||
void copyFrom(const DenseMapBase<OtherBaseT, KeyT, ValueT, KeyInfoT>& other) {
|
void copyFrom(const DenseMapBase<OtherBaseT, KeyT, ValueT, KeyInfoT>& other) {
|
||||||
|
assert(&other != this);
|
||||||
assert(getNumBuckets() == other.getNumBuckets());
|
assert(getNumBuckets() == other.getNumBuckets());
|
||||||
|
|
||||||
setNumEntries(other.getNumEntries());
|
setNumEntries(other.getNumEntries());
|
||||||
@@ -574,7 +575,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
DenseMap& operator=(const DenseMap& other) {
|
DenseMap& operator=(const DenseMap& other) {
|
||||||
copyFrom(other);
|
if (&other != this)
|
||||||
|
copyFrom(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -799,7 +801,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
SmallDenseMap& operator=(const SmallDenseMap& other) {
|
SmallDenseMap& operator=(const SmallDenseMap& other) {
|
||||||
copyFrom(other);
|
if (&other != this)
|
||||||
|
copyFrom(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -244,6 +244,11 @@ TYPED_TEST(DenseMapTest, AssignmentTest) {
|
|||||||
|
|
||||||
EXPECT_EQ(1u, copyMap.size());
|
EXPECT_EQ(1u, copyMap.size());
|
||||||
EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
|
EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
|
||||||
|
|
||||||
|
// test self-assignment.
|
||||||
|
copyMap = copyMap;
|
||||||
|
EXPECT_EQ(1u, copyMap.size());
|
||||||
|
EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test swap method
|
// Test swap method
|
||||||
|
Reference in New Issue
Block a user