Containers: destroy previous state on move-assignment immediately

[ChangeLog][QtCore] All generic containers (with the exception of
QVarLengthArray, but including QSharedPointer) destroy the
previous state as part of a move-assignment now. Previously, they
would dump it into the right-hand-side object. Note that this is
only true for the generic containers. Other implicitly-shared
types, as well as the non-generic containers QString, QByteArray,
etc. still just swap the contents with the right-hand-side object
when move-assigned into, and, for performance reasons, this will
not change in the forseeable future.

Change-Id: I1f1c684e85400b77bd2e7fba65bde2dce6c1bdde
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2015-07-03 13:24:31 +02:00
parent 8ab2d86d05
commit 27ba0b8f88
5 changed files with 6 additions and 5 deletions

View File

@ -249,7 +249,7 @@ public:
#ifdef Q_COMPILER_RVALUE_REFS
QHash(QHash &&other) Q_DECL_NOTHROW : d(other.d) { other.d = const_cast<QHashData *>(&QHashData::shared_null); }
QHash &operator=(QHash &&other) Q_DECL_NOTHROW
{ qSwap(d, other.d); return *this; }
{ QHash moved(std::move(other)); swap(moved); return *this; }
#endif
void swap(QHash &other) Q_DECL_NOTHROW { qSwap(d, other.d); }

View File

@ -88,7 +88,7 @@ public:
#ifdef Q_COMPILER_RVALUE_REFS
inline QLinkedList(QLinkedList<T> &&other) : d(other.d) { other.d = const_cast<QLinkedListData *>(&QLinkedListData::shared_null); }
inline QLinkedList<T> &operator=(QLinkedList<T> &&other)
{ qSwap(d, other.d); return *this; }
{ QLinkedList moved(std::move(other)); swap(moved); return *this; }
#endif
inline void swap(QLinkedList<T> &other) { qSwap(d, other.d); }
bool operator==(const QLinkedList<T> &l) const;

View File

@ -144,7 +144,7 @@ public:
#ifdef Q_COMPILER_RVALUE_REFS
inline QList(QList<T> &&other) : d(other.d) { other.d = const_cast<QListData::Data *>(&QListData::shared_null); }
inline QList &operator=(QList<T> &&other)
{ qSwap(d, other.d); return *this; }
{ QList moved(std::move(other)); swap(moved); return *this; }
#endif
inline void swap(QList<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS

View File

@ -344,7 +344,7 @@ public:
}
inline QMap<Key, T> &operator=(QMap<Key, T> &&other)
{ qSwap(d, other.d); return *this; }
{ QMap moved(std::move(other)); swap(moved); return *this; }
#endif
inline void swap(QMap<Key, T> &other) { qSwap(d, other.d); }
explicit QMap(const typename std::map<Key, T> &other);

View File

@ -70,7 +70,8 @@ public:
QVector<T> &operator=(const QVector<T> &v);
#ifdef Q_COMPILER_RVALUE_REFS
QVector(QVector<T> &&other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); }
QVector<T> &operator=(QVector<T> &&other) Q_DECL_NOTHROW { swap(other); return *this; }
QVector<T> &operator=(QVector<T> &&other) Q_DECL_NOTHROW
{ QVector moved(std::move(other)); swap(moved); return *this; }
#endif
void swap(QVector<T> &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS