From c6e1b54f94e84950ee12c3bb2be0641f5742056b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 24 Jan 2020 09:09:01 +0100 Subject: [PATCH] Cleanup code where we mixed QHash and QMultiHash iterator code Change-Id: Ib229cad13ca21d6288e009c6ee1c39fa974f80b8 Reviewed-by: Simon Hausmann --- src/tools/moc/generator.cpp | 2 +- src/tools/rcc/rcc.cpp | 20 +++++-------- src/widgets/widgets/qwidgettextcontrol.cpp | 2 +- src/xml/dom/qdom.cpp | 12 ++++---- .../qsharedpointer/tst_qsharedpointer.cpp | 30 +++++++++++-------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index f41b0e8ba4..93bc4d8c4e 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -476,7 +476,7 @@ void Generator::generateCode() QByteArray unqualifiedScope = p.type.left(s); // The scope may be a namespace for example, so it's only safe to include scopes that are known QObjects (QTBUG-2151) - QHash::ConstIterator scopeIt; + QMultiHash::ConstIterator scopeIt; QByteArray thisScope = cdef->qualified; do { diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 7188c81300..5bd1fba272 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -744,10 +744,9 @@ bool RCCResourceLibrary::addFile(const QString &alias, const RCCFileInfo &file) const QString filename = nodes.at(nodes.size()-1); RCCFileInfo *s = new RCCFileInfo(file); s->m_parent = parent; - typedef QHash::const_iterator ChildConstIterator; - const ChildConstIterator cbegin = parent->m_children.constFind(filename); - const ChildConstIterator cend = parent->m_children.constEnd(); - for (ChildConstIterator it = cbegin; it != cend; ++it) { + auto cbegin = parent->m_children.constFind(filename); + auto cend = parent->m_children.constEnd(); + for (auto it = cbegin; it != cend; ++it) { if (it.key() == filename && it.value()->m_language == s->m_language && it.value()->m_country == s->m_country) { for (const QString &name : qAsConst(m_fileNames)) { @@ -823,7 +822,7 @@ QStringList RCCResourceLibrary::dataFiles() const pending.push(m_root); while (!pending.isEmpty()) { RCCFileInfo *file = pending.pop(); - for (QHash::iterator it = file->m_children.begin(); + for (auto it = file->m_children.begin(); it != file->m_children.end(); ++it) { RCCFileInfo *child = it.value(); if (child->m_flags & RCCFileInfo::Directory) @@ -838,10 +837,9 @@ QStringList RCCResourceLibrary::dataFiles() const // Determine map of resource identifier (':/newPrefix/images/p1.png') to file via recursion static void resourceDataFileMapRecursion(const RCCFileInfo *m_root, const QString &path, RCCResourceLibrary::ResourceDataFileMap &m) { - typedef QHash::const_iterator ChildConstIterator; const QChar slash = QLatin1Char('/'); - const ChildConstIterator cend = m_root->m_children.constEnd(); - for (ChildConstIterator it = m_root->m_children.constBegin(); it != cend; ++it) { + const auto cend = m_root->m_children.constEnd(); + for (auto it = m_root->m_children.constBegin(); it != cend; ++it) { const RCCFileInfo *child = it.value(); const QString childName = path + slash + child->m_name; if (child->m_flags & RCCFileInfo::Directory) { @@ -1149,8 +1147,7 @@ bool RCCResourceLibrary::writeDataBlobs() QString errorMessage; while (!pending.isEmpty()) { RCCFileInfo *file = pending.pop(); - for (QHash::iterator it = file->m_children.begin(); - it != file->m_children.end(); ++it) { + for (auto it = file->m_children.cbegin(); it != file->m_children.cend(); ++it) { RCCFileInfo *child = it.value(); if (child->m_flags & RCCFileInfo::Directory) pending.push(child); @@ -1214,8 +1211,7 @@ bool RCCResourceLibrary::writeDataNames() qint64 offset = 0; while (!pending.isEmpty()) { RCCFileInfo *file = pending.pop(); - for (QHash::iterator it = file->m_children.begin(); - it != file->m_children.end(); ++it) { + for (auto it = file->m_children.cbegin(); it != file->m_children.cend(); ++it) { RCCFileInfo *child = it.value(); if (child->m_flags & RCCFileInfo::Directory) pending.push(child); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 3da7e365c8..f8bccfbfa3 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -2512,7 +2512,7 @@ void QWidgetTextControl::setExtraSelections(const QList::iterator it = hash.begin(); it != hash.end(); ++it) { + for (auto it = hash.cbegin(); it != hash.cend(); ++it) { const QAbstractTextDocumentLayout::Selection &esel = d->extraSelections.at(it.value()); QRectF r = selectionRect(esel.cursor); if (esel.format.boolProperty(QTextFormat::FullWidthSelection)) { diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 647e22bf26..1ac13b380a 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -2550,7 +2550,7 @@ QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p) m->readonly = readonly; m->appendToParent = appendToParent; - QHash::const_iterator it = map.constBegin(); + auto it = map.constBegin(); for (; it != map.constEnd(); ++it) { QDomNodePrivate *new_node = (*it)->cloneNode(); new_node->setParent(p); @@ -2566,7 +2566,7 @@ void QDomNamedNodeMapPrivate::clearMap() { // Dereference all of our children if we took references if (!appendToParent) { - QHash::const_iterator it = map.constBegin(); + auto it = map.constBegin(); for (; it != map.constEnd(); ++it) if (!(*it)->ref.deref()) delete *it; @@ -2582,7 +2582,7 @@ QDomNodePrivate* QDomNamedNodeMapPrivate::namedItem(const QString& name) const QDomNodePrivate* QDomNamedNodeMapPrivate::namedItemNS(const QString& nsURI, const QString& localName) const { - QHash::const_iterator it = map.constBegin(); + auto it = map.constBegin(); QDomNodePrivate *n; for (; it != map.constEnd(); ++it) { n = *it; @@ -3098,11 +3098,11 @@ void QDomDocumentTypePrivate::save(QTextStream& s, int, int indent) const if (entities->length()>0 || notations->length()>0) { s << " [" << Qt::endl; - QHash::const_iterator it2 = notations->map.constBegin(); + auto it2 = notations->map.constBegin(); for (; it2 != notations->map.constEnd(); ++it2) (*it2)->save(s, 0, indent); - QHash::const_iterator it = entities->map.constBegin(); + auto it = entities->map.constBegin(); for (; it != entities->map.constEnd(); ++it) (*it)->save(s, 0, indent); @@ -4088,7 +4088,7 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const /* Write out attributes. */ if (!m_attr->map.isEmpty()) { QDuplicateTracker outputtedPrefixes; - QHash::const_iterator it = m_attr->map.constBegin(); + auto it = m_attr->map.constBegin(); for (; it != m_attr->map.constEnd(); ++it) { s << ' '; if (it.value()->namespaceURI.isNull()) { diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index a9fd282ac9..8a621cd5d9 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -2155,7 +2155,7 @@ void tst_QSharedPointer::threadStressTest() } } -template +template void hashAndMapTest() { typedef typename Container::key_type Key; @@ -2200,26 +2200,30 @@ void hashAndMapTest() QVERIFY(it == c.end()); } - c.insertMulti(k1, Value(47)); - it = c.find(k1); - QVERIFY(it != c.end()); - QCOMPARE(it.key(), k1); - ++it; - QVERIFY(it != c.end()); - QCOMPARE(it.key(), k1); - ++it; - if (Ordered) - QVERIFY(it == c.end()); + if (Multi) { + c.insert(k1, Value(47)); + it = c.find(k1); + QVERIFY(it != c.end()); + QCOMPARE(it.key(), k1); + ++it; + QVERIFY(it != c.end()); + QCOMPARE(it.key(), k1); + ++it; + if (Ordered) + QVERIFY(it == c.end()); + } } void tst_QSharedPointer::map() { - hashAndMapTest, int>, true>(); + hashAndMapTest, int>, true, false>(); + hashAndMapTest, int>, true, true>(); } void tst_QSharedPointer::hash() { - hashAndMapTest, int>, false>(); + hashAndMapTest, int>, false, false>(); + hashAndMapTest, int>, false, true>(); } void tst_QSharedPointer::validConstructs()