Cleanup code where we mixed QHash and QMultiHash iterator code

Change-Id: Ib229cad13ca21d6288e009c6ee1c39fa974f80b8
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Lars Knoll 2020-01-24 09:09:01 +01:00
parent 7f67e91e55
commit c6e1b54f94
5 changed files with 33 additions and 33 deletions

View File

@ -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<QByteArray, QByteArray>::ConstIterator scopeIt;
QMultiHash<QByteArray, QByteArray>::ConstIterator scopeIt;
QByteArray thisScope = cdef->qualified;
do {

View File

@ -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<QString, RCCFileInfo*>::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<QString, RCCFileInfo*>::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<QString, RCCFileInfo*>::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<QString, RCCFileInfo*>::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<QString, RCCFileInfo*>::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);

View File

@ -2512,7 +2512,7 @@ void QWidgetTextControl::setExtraSelections(const QList<QTextEdit::ExtraSelectio
emit updateRequest(r);
}
for (QHash<int, int>::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)) {

View File

@ -2550,7 +2550,7 @@ QDomNamedNodeMapPrivate* QDomNamedNodeMapPrivate::clone(QDomNodePrivate* p)
m->readonly = readonly;
m->appendToParent = appendToParent;
QHash<QString, QDomNodePrivate*>::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<QString, QDomNodePrivate *>::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<QString, QDomNodePrivate *>::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<QString, QDomNodePrivate *>::const_iterator it2 = notations->map.constBegin();
auto it2 = notations->map.constBegin();
for (; it2 != notations->map.constEnd(); ++it2)
(*it2)->save(s, 0, indent);
QHash<QString, QDomNodePrivate *>::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<QString> outputtedPrefixes;
QHash<QString, QDomNodePrivate *>::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()) {

View File

@ -2155,7 +2155,7 @@ void tst_QSharedPointer::threadStressTest()
}
}
template<typename Container, bool Ordered>
template<typename Container, bool Ordered, bool Multi>
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<QMap<QSharedPointer<int>, int>, true>();
hashAndMapTest<QMap<QSharedPointer<int>, int>, true, false>();
hashAndMapTest<QMultiMap<QSharedPointer<int>, int>, true, true>();
}
void tst_QSharedPointer::hash()
{
hashAndMapTest<QHash<QSharedPointer<int>, int>, false>();
hashAndMapTest<QHash<QSharedPointer<int>, int>, false, false>();
hashAndMapTest<QMultiHash<QSharedPointer<int>, int>, false, true>();
}
void tst_QSharedPointer::validConstructs()