From 3e803b5180e7059c01c15ea84cadd54982e1a221 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 11:37:37 +0100 Subject: QCollator: enable move semantics This necessitates adding d==0 checks in QCollator. By documenting that moved-from instances can only be assigned to or destroyed, we can limit the functions in which to check for d==0 to the assignment operator and the destructor. Doing otherwise would destroy all advantages of move semantics by introducing a heap allocation to re-populate other.d. Add a test for this (QCollator didn't have any before). Change-Id: Ic6ff202072822bebfd5e48259c3d0fa345a63118 Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools/qcollator.cpp') diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index cfb5fe77ae..80d330bfca 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -99,7 +99,7 @@ QCollator::QCollator(const QCollator &other) */ QCollator::~QCollator() { - if (!d->ref.deref()) + if (d && !d->ref.deref()) delete d; } @@ -109,14 +109,34 @@ QCollator::~QCollator() QCollator &QCollator::operator=(const QCollator &other) { if (this != &other) { - if (!d->ref.deref()) + if (d && !d->ref.deref()) delete d; d = other.d; - d->ref.ref(); + if (d) d->ref.ref(); } return *this; } +/* + \fn void QCollator::QCollator(QCollator &&other) + + Move constructor. Moves from \a other into this collator. + + Note that a moved-from QCollator can only be destroyed or assigned + to. The effect of calling other functions than the destructor or + one of the assignment operators is undefined. +*/ + +/* + \fn QCollator &QCollator::operator=(QCollator &&other) + + Move-assigns from \a other to this collator. + + Note that a moved-from QCollator can only be destroyed or assigned + to. The effect of calling other functions than the destructor or + one of the assignment operators is undefined. +*/ + /*! \fn void QCollator::swap(QCollator &other) -- cgit v1.2.3