From 514972544a34aca0fd679b3a78521a0a1558d4e0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 31 May 2018 20:13:05 -0700 Subject: QCborArray & Map: implement move semantics There isn't a lot of efficiency gain, since QCborValue was already refcounted. This saves two atomic operations and an out-of-line call. In the case of QCborValueRef (which includes QCborMap), because we reset the container pointer in inline code, the call to QCborValue::dispose() is also suppressed. Change-Id: Icc2c231dc2c44abdb087fffd1533eaba7a9c70fa Reviewed-by: Simon Hausmann --- src/corelib/serialization/qcborarray.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/corelib/serialization/qcborarray.cpp') diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp index a1b0d1573c..e35738adcc 100644 --- a/src/corelib/serialization/qcborarray.cpp +++ b/src/corelib/serialization/qcborarray.cpp @@ -298,6 +298,9 @@ QCborValue QCborArray::at(qsizetype i) const */ /*! + \fn void QCborArray::insert(qsizetype i, const QCborValue &value) + \fn void QCborArray::insert(qsizetype i, QCborValue &&value) + Inserts \a value into the array at position \a i in this array. The array must have at least \a i elements before the insertion. @@ -313,6 +316,16 @@ void QCborArray::insert(qsizetype i, const QCborValue &value) d->insertAt(i, value); } +void QCborArray::insert(qsizetype i, QCborValue &&value) +{ + Q_ASSERT(size_t(i) <= size_t(size()) || i == -1); + if (i < 0) + i = size(); + detach(qMax(i + 1, size())); + d->insertAt(i, value, QCborContainerPrivate::MoveContainer); + QCborContainerPrivate::resetValue(value); +} + /*! Extracts a value from the array at the position indicated by iterator \a it and returns the value so extracted. @@ -330,6 +343,7 @@ QCborValue QCborArray::extract(iterator it) /*! \fn void QCborArray::prepend(const QCborValue &value) + \fn void QCborArray::prepend(QCborValue &&value) Prepends \a value into the array before any other elements it may already contain. @@ -340,6 +354,7 @@ QCborValue QCborArray::extract(iterator it) /*! \fn void QCborArray::append(const QCborValue &value) + \fn void QCborArray::append(QCborValue &&value) Appends \a value into the array after all other elements it may already contain. -- cgit v1.2.3