mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Lift self-copy protection up to the header file and add self-move
protection to the same layer. This is in line with Howard's advice on how best to handle self-move assignment as he explained on SO[1]. It also ensures that implementing swap with move assignment continues to work in the case of self-swap. [1]: http://stackoverflow.com/questions/9322174/move-assignment-operator-and-if-this-rhs llvm-svn: 195705
This commit is contained in:
parent
9233af88ac
commit
dc82f92af7
@ -293,14 +293,16 @@ public:
|
|||||||
|
|
||||||
SmallPtrSet<PtrType, SmallSize> &
|
SmallPtrSet<PtrType, SmallSize> &
|
||||||
operator=(const SmallPtrSet<PtrType, SmallSize> &RHS) {
|
operator=(const SmallPtrSet<PtrType, SmallSize> &RHS) {
|
||||||
CopyFrom(RHS);
|
if (&RHS != this)
|
||||||
|
CopyFrom(RHS);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LLVM_HAS_RVALUE_REFERENCES
|
#if LLVM_HAS_RVALUE_REFERENCES
|
||||||
SmallPtrSet<PtrType, SmallSize>&
|
SmallPtrSet<PtrType, SmallSize>&
|
||||||
operator=(SmallPtrSet<PtrType, SmallSize> &&RHS) {
|
operator=(SmallPtrSet<PtrType, SmallSize> &&RHS) {
|
||||||
MoveFrom(SmallSizePowTwo, std::move(RHS));
|
if (&RHS != this)
|
||||||
|
MoveFrom(SmallSizePowTwo, std::move(RHS));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -218,8 +218,7 @@ SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize,
|
|||||||
/// CopyFrom - implement operator= from a smallptrset that has the same pointer
|
/// CopyFrom - implement operator= from a smallptrset that has the same pointer
|
||||||
/// type, but may have a different small size.
|
/// type, but may have a different small size.
|
||||||
void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
|
void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
|
||||||
if (&RHS == this)
|
assert(&RHS != this && "Self-copy should be handled by the caller.");
|
||||||
return;
|
|
||||||
|
|
||||||
if (isSmall() && RHS.isSmall())
|
if (isSmall() && RHS.isSmall())
|
||||||
assert(CurArraySize == RHS.CurArraySize &&
|
assert(CurArraySize == RHS.CurArraySize &&
|
||||||
@ -256,6 +255,8 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
|
|||||||
|
|
||||||
#if LLVM_HAS_RVALUE_REFERENCES
|
#if LLVM_HAS_RVALUE_REFERENCES
|
||||||
void SmallPtrSetImpl::MoveFrom(unsigned SmallSize, SmallPtrSetImpl &&RHS) {
|
void SmallPtrSetImpl::MoveFrom(unsigned SmallSize, SmallPtrSetImpl &&RHS) {
|
||||||
|
assert(&RHS != this && "Self-move should be handled by the caller.");
|
||||||
|
|
||||||
if (!isSmall())
|
if (!isSmall())
|
||||||
free(CurArray);
|
free(CurArray);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user