From 2bb44414ff456873c885391e4a03afb67e7306da Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 19 May 2018 14:58:43 -0700 Subject: 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 Reviewed-by: Thiago Macieira --- src/corelib/serialization/qcbormap.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/corelib/serialization/qcbormap.h') diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h index 9499f46ace..89de3d6786 100644 --- a/src/corelib/serialization/qcbormap.h +++ b/src/corelib/serialization/qcbormap.h @@ -207,6 +207,14 @@ public: QCborValueRef operator[](const QString & key); QCborValueRef operator[](const QCborValue &key); + QCborValue take(qint64 key) + { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } + QCborValue take(QLatin1String key) + { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } + QCborValue take(const QString &key) + { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } + QCborValue take(const QCborValue &key) + { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } void remove(qint64 key) { iterator it = find(key); if (it != end()) erase(it); } void remove(QLatin1String key) @@ -254,6 +262,8 @@ public: const_iterator cend() const { return constEnd(); } iterator erase(iterator it); iterator erase(const_iterator it) { return erase(iterator{ it.item.d, it.item.i }); } + QCborValue extract(iterator it); + QCborValue extract(const_iterator it) { return extract(iterator{ it.item.d, it.item.i }); } bool empty() const { return isEmpty(); } iterator find(qint64 key); -- cgit v1.2.3