diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-10-09 01:00:47 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-10-09 01:00:48 +0200 |
commit | 69b6845edbb43cf7000942d07f3a326383bdf6d2 (patch) | |
tree | 58755c33dfb18a51d194d0f774b1deca6135ce4a /src/corelib/serialization/qcborarray.cpp | |
parent | e2ab24d36f31395c2239b49ac26f2266b69444bd (diff) | |
parent | 8e5a2f63c3f6ee49d3f2e1985bf73de7769b0e72 (diff) |
Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: I5cbfd39cf728036bbdfdeec8e8739568e0a3025b
Diffstat (limited to 'src/corelib/serialization/qcborarray.cpp')
-rw-r--r-- | src/corelib/serialization/qcborarray.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp index c8df594c07..28ae40f3df 100644 --- a/src/corelib/serialization/qcborarray.cpp +++ b/src/corelib/serialization/qcborarray.cpp @@ -298,7 +298,8 @@ QCborValue QCborArray::at(qsizetype i) const \fn QCborValueRef QCborArray::operator[](qsizetype i) Returns a reference to the QCborValue element at position \a i in the - array. The array must have at least \a i elements. + array. Indices beyond the end of the array will grow the array, filling + with undefined entries, until it has an entry at the specified index. QCborValueRef has the exact same API as \l QCborValue, with one important difference: if you assign new values to it, this map will be updated with @@ -312,27 +313,34 @@ 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. + Inserts \a value into the array at position \a i in this array. If \a i is + -1, the entry is appended to the array. Pads the array with invalid entries + if \a i is greater than the prior size of the array. \sa at(), operator[](), first(), last(), prepend(), append(), removeAt(), takeAt(), extract() */ void QCborArray::insert(qsizetype i, const QCborValue &value) { - Q_ASSERT(size_t(i) <= size_t(size()) || i == -1); - if (i < 0) + if (i < 0) { + Q_ASSERT(i == -1); i = size(); - detach(qMax(i + 1, size())); + detach(i + 1); + } else { + d = QCborContainerPrivate::grow(d.data(), i); // detaches + } d->insertAt(i, value); } void QCborArray::insert(qsizetype i, QCborValue &&value) { - Q_ASSERT(size_t(i) <= size_t(size()) || i == -1); - if (i < 0) + if (i < 0) { + Q_ASSERT(i == -1); i = size(); - detach(qMax(i + 1, size())); + detach(i + 1); + } else { + d = QCborContainerPrivate::grow(d.data(), i); // detaches + } d->insertAt(i, value, QCborContainerPrivate::MoveContainer); QCborContainerPrivate::resetValue(value); } |