From 27ba0b8f88c32b800270b13672fc2260f8d2d28f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 3 Jul 2015 13:24:31 +0200 Subject: 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 Reviewed-by: Thiago Macieira --- src/corelib/tools/qvector.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib/tools/qvector.h') diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 2adb047ed9..624d828a3b 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -70,7 +70,8 @@ public: QVector &operator=(const QVector &v); #ifdef Q_COMPILER_RVALUE_REFS QVector(QVector &&other) Q_DECL_NOTHROW : d(other.d) { other.d = Data::sharedNull(); } - QVector &operator=(QVector &&other) Q_DECL_NOTHROW { swap(other); return *this; } + QVector &operator=(QVector &&other) Q_DECL_NOTHROW + { QVector moved(std::move(other)); swap(moved); return *this; } #endif void swap(QVector &other) Q_DECL_NOTHROW { qSwap(d, other.d); } #ifdef Q_COMPILER_INITIALIZER_LISTS -- cgit v1.2.3