From 82eff42b7ba6f75ac2a17e42f1756f645b529ddc Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 3 Nov 2022 20:37:38 +0100 Subject: [PATCH] QDomDocument: use .value() instead of dereferencing an iterator Do not assume that, given an iterator into an associative container, you can write `*it`. Use `it.value()` instead. This is done in preparation for the next commit. Also, drop the const-prefix from functions (find, begin) where they operate on a const container already. Change-Id: I2cafc884666d98c240c2fdc661c9068c4c7319e1 Reviewed-by: Marc Mutz --- src/xml/dom/qdom.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 6b86d3641cb..e8e2e5902a6 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -2523,7 +2523,7 @@ QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) auto it = map.constBegin(); for (; it != map.constEnd(); ++it) { - QDomNodePrivate *new_node = (*it)->cloneNode(); + QDomNodePrivate *new_node = it.value()->cloneNode(); new_node->setParent(p); m->setNamedItem(new_node); } @@ -2539,16 +2539,16 @@ void QDomNamedNodeMapPrivate::clearMap() if (!appendToParent) { auto it = map.constBegin(); for (; it != map.constEnd(); ++it) - if (!(*it)->ref.deref()) - delete *it; + if (!it.value()->ref.deref()) + delete it.value(); } map.clear(); } QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem(const QString& name) const { - auto it = map.constFind(name); - return it == map.cend() ? nullptr : *it; + auto it = map.find(name); + return it == map.end() ? nullptr : it.value(); } QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, const QString& localName) const @@ -2556,7 +2556,7 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, cons auto it = map.constBegin(); QDomNodePrivate *n; for (; it != map.constEnd(); ++it) { - n = *it; + n = it.value(); if (!n->prefix.isNull()) { // node has a namespace if (n->namespaceURI == nsURI && n->name == localName) @@ -2623,7 +2623,7 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::item(int index) const { if (index >= length() || index < 0) return nullptr; - return *std::next(map.cbegin(), index); + return std::next(map.begin(), index).value(); } int QDomNamedNodeMapPrivate::length() const @@ -3069,11 +3069,11 @@ void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const auto it2 = notations->map.constBegin(); for (; it2 != notations->map.constEnd(); ++it2) - (*it2)->save(s, 0, indent); + it2.value()->save(s, 0, indent); auto it = entities->map.constBegin(); for (; it != entities->map.constEnd(); ++it) - (*it)->save(s, 0, indent); + it.value()->save(s, 0, indent); s << ']'; }