diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2018-05-19 14:58:43 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-07-04 03:04:21 +0000 |
commit | 2bb44414ff456873c885391e4a03afb67e7306da (patch) | |
tree | 9d6f7d1b2912cd494073c10e23fd61543535a022 /src/corelib/serialization/qcborarray.cpp | |
parent | fcb0f68e77bb69544f0ae310baffd3ceff8a9e5d (diff) |
QCborArray & Map: implement efficient take() / extract()
Questions:
1) should QCborMap::extract return value_type (a pair) instead of just
the value?
2) should the both return the iterator to the next element too, like
erase()?
Change-Id: I052407b777ec43f78378fffd15302a9c14468db3
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qcborarray.cpp')
-rw-r--r-- | src/corelib/serialization/qcborarray.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp index 020841d604..a1b0d1573c 100644 --- a/src/corelib/serialization/qcborarray.cpp +++ b/src/corelib/serialization/qcborarray.cpp @@ -42,6 +42,8 @@ QT_BEGIN_NAMESPACE +using namespace QtCbor; + /*! \class QCborArray \inmodule QtCore @@ -300,7 +302,7 @@ QCborValue QCborArray::at(qsizetype i) const must have at least \a i elements before the insertion. \sa at(), operator[](), first(), last(), prepend(), append(), - removeAt(), takeAt() + removeAt(), takeAt(), extract() */ void QCborArray::insert(qsizetype i, const QCborValue &value) { @@ -312,6 +314,21 @@ void QCborArray::insert(qsizetype i, const QCborValue &value) } /*! + Extracts a value from the array at the position indicated by iterator \a it + and returns the value so extracted. + + \sa insert(), erase(), takeAt(), removeAt() + */ +QCborValue QCborArray::extract(iterator it) +{ + detach(); + + QCborValue v = d->extractAt(it.item.i); + d->removeAt(it.item.i); + return v; +} + +/*! \fn void QCborArray::prepend(const QCborValue &value) Prepends \a value into the array before any other elements it may already |