diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2018-05-31 20:13:05 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-07-05 14:56:15 +0000 |
commit | 514972544a34aca0fd679b3a78521a0a1558d4e0 (patch) | |
tree | 8dbec4023d90d4022256071fadad39d67723c3c4 /src/corelib/serialization/qcborarray.cpp | |
parent | fddf09363e1bbc6f6549eaf28def7699b2d87341 (diff) |
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/serialization/qcborarray.cpp')
-rw-r--r-- | src/corelib/serialization/qcborarray.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
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. |