From f4950cb6e15a7a6c1a6732c9a5ec9d59a2952948 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 8 Jul 2018 19:33:02 -0700 Subject: QCborMap: make take() & remove() efficient if the item isn't there By using constFind(), we won't detach if the item isn't there. Both extract() and erase() can take const_iterators. Change-Id: Id59bdd8f1a804b809e22fffd153f92989ef84644 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/serialization/qcbormap.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/corelib/serialization/qcbormap.h') diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h index 15c9a5c50c..02c2ec086d 100644 --- a/src/corelib/serialization/qcbormap.h +++ b/src/corelib/serialization/qcbormap.h @@ -208,21 +208,21 @@ public: QCborValueRef operator[](const QCborValue &key); QCborValue take(qint64 key) - { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } + { const_iterator it = constFind(key); if (it != constEnd()) return extract(it); return QCborValue(); } QCborValue take(QLatin1String key) - { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } + { const_iterator it = constFind(key); if (it != constEnd()) return extract(it); return QCborValue(); } QCborValue take(const QString &key) - { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } + { const_iterator it = constFind(key); if (it != constEnd()) return extract(it); return QCborValue(); } QCborValue take(const QCborValue &key) - { iterator it = find(key); if (it != end()) return extract(it); return QCborValue(); } + { const_iterator it = constFind(key); if (it != constEnd()) return extract(it); return QCborValue(); } void remove(qint64 key) - { iterator it = find(key); if (it != end()) erase(it); } + { const_iterator it = constFind(key); if (it != constEnd()) erase(it); } void remove(QLatin1String key) - { iterator it = find(key); if (it != end()) erase(it); } + { const_iterator it = constFind(key); if (it != constEnd()) erase(it); } void remove(const QString & key) - { iterator it = find(key); if (it != end()) erase(it); } + { const_iterator it = constFind(key); if (it != constEnd()) erase(it); } void remove(const QCborValue &key) - { iterator it = find(key); if (it != end()) erase(it); } + { const_iterator it = constFind(key); if (it != constEnd()) erase(it); } bool contains(qint64 key) const { const_iterator it = find(key); return it != end(); } bool contains(QLatin1String key) const -- cgit v1.2.3