diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-09-04 16:55:29 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-09-20 17:19:31 +0000 |
commit | b1b57225dbc8733935697e1895631969e9a95376 (patch) | |
tree | 0a7f40c74bd90e83f6600ed361f7ace81b4e6f86 /src/xmlpatterns/schema | |
parent | dba42c925db368aa958c38c6a3481f18a57bd71f (diff) | |
download | qtxmlpatterns-b1b57225dbc8733935697e1895631969e9a95376.tar.gz |
Eradicate Java-style loops (II): QSetIterator -> C++11 ranged for
Java-style iterators are slower than STL-style ones, so they
should not be used in library code.
Replaced them with C++11 ranged for loops, adding qAsConst()
as needed.
Change-Id: I21b59daceafc62b94ebba56bfef1f050988b9c9f
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/xmlpatterns/schema')
-rw-r--r-- | src/xmlpatterns/schema/qxsdschemachecker.cpp | 5 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdstatemachine_p.h | 4 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h | 12 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp | 25 |
4 files changed, 12 insertions, 34 deletions
diff --git a/src/xmlpatterns/schema/qxsdschemachecker.cpp b/src/xmlpatterns/schema/qxsdschemachecker.cpp index b6e51f3..0898848 100644 --- a/src/xmlpatterns/schema/qxsdschemachecker.cpp +++ b/src/xmlpatterns/schema/qxsdschemachecker.cpp @@ -1694,9 +1694,8 @@ void XsdSchemaChecker::checkDuplicatedAttributeUses() void XsdSchemaChecker::checkElementConstraints() { const QSet<XsdElement::Ptr> elements = collectAllElements(m_schema); - QSetIterator<XsdElement::Ptr> it(elements); - while (it.hasNext()) { - const XsdElement::Ptr element = it.next(); + + for (const XsdElement::Ptr &element : elements) { // @see http://www.w3.org/TR/xmlschema11-1/#e-props-correct diff --git a/src/xmlpatterns/schema/qxsdstatemachine_p.h b/src/xmlpatterns/schema/qxsdstatemachine_p.h index 0ec8eb4..e535c8b 100644 --- a/src/xmlpatterns/schema/qxsdstatemachine_p.h +++ b/src/xmlpatterns/schema/qxsdstatemachine_p.h @@ -261,9 +261,7 @@ namespace QPatternist { QSet<StateId> result; - QSetIterator<StateId> it(states); - while (it.hasNext()) { // iterate over all given states - const StateId state = it.next(); + for (const StateId state : states) { // get the transition table for the current state const QHash<TransitionType, QVector<StateId> > transitions = m_transitions.value(state); diff --git a/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h b/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h index 91424a8..b989584 100644 --- a/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h +++ b/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h @@ -320,11 +320,9 @@ typename XsdStateMachine<TransitionType>::StateId XsdStateMachine<TransitionType // state, in that case our new DFA state will be a // Start or End state as well StateType type = InternalState; - QSetIterator<StateId> it(nfaState); bool hasStartState = false; bool hasEndState = false; - while (it.hasNext()) { - const StateId state = it.next(); + for (const StateId state : qAsConst(nfaState)) { if (m_states.value(state) == EndState) { hasEndState = true; } else if (m_states.value(state) == StartState) { @@ -390,12 +388,8 @@ XsdStateMachine<TransitionType> XsdStateMachine<TransitionType>::toDFA() const // the 'states' set QList<TransitionType> input; - { - QSetIterator<StateId> it(states); - while (it.hasNext()) { - input << m_transitions.value(it.next()).keys(); - } - } + for (const StateId state : states) + input << m_transitions.value(state).keys(); // get the state in DFA that corresponds to the 'states' set in the NFA const StateId dfaBegin = dfaStateForNfaState(states, table, dfa); diff --git a/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp b/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp index 7cb925a..bf33af1 100644 --- a/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp +++ b/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp @@ -167,9 +167,7 @@ bool XsdValidatingInstanceReader::read() // check IDREF occurrences const QStringList ids = m_model->idIdRefBindingIds(); - QSetIterator<QString> it(m_idRefs); - while (it.hasNext()) { - const QString id = it.next(); + for (const QString &id : qAsConst(m_idRefs)) { if (!ids.contains(id)) { error(QtXmlPatterns::tr("There is one IDREF value with no corresponding ID: %1.").arg(formatKeyword(id))); return false; @@ -750,9 +748,7 @@ bool XsdValidatingInstanceReader::validateElementComplexType(const XsdElement::P bool hasIDAttribute = hasIDAttributeUse(complexType->attributeUses()); // 2 - QSetIterator<QXmlName> it(attributes); - while (it.hasNext()) { - const QXmlName attributeName = it.next(); + for (const QXmlName &attributeName : attributes) { // skip builtin attributes if (attributeName == m_xsiNilName || @@ -1005,9 +1001,7 @@ bool XsdValidatingInstanceReader::validateKeyIdentityConstraint(const XsdElement return false; // 4.2.3 - QSetIterator<TargetNode> it(qualifiedNodeSet); - while (it.hasNext()) { - const TargetNode node = it.next(); + for (const TargetNode node : qualifiedNodeSet) { const QVector<QXmlItem> fieldItems = node.fieldItems(); for (int i = 0; i < fieldItems.count(); ++i) { const QXmlNodeModelIndex index = fieldItems.at(i).toNodeModelIndex(); @@ -1037,16 +1031,11 @@ bool XsdValidatingInstanceReader::validateKeyRefIdentityConstraint(const XsdElem const TargetNode::Set keySet = m_idcKeys.value(constraint->referencedKey()->name(m_namePool)); - QSetIterator<TargetNode> it(qualifiedNodeSet); - while (it.hasNext()) { - const TargetNode node = it.next(); + for (const TargetNode &node : qualifiedNodeSet) { bool foundMatching = false; - QSetIterator<TargetNode> keyIt(keySet); - while (keyIt.hasNext()) { - const TargetNode keyNode = keyIt.next(); - + for (const TargetNode &keyNode : keySet) { if (node.fieldsAreEqual(keyNode, m_namePool, m_context, &reflection)) { foundMatching = true; break; @@ -1179,9 +1168,7 @@ bool XsdValidatingInstanceReader::selectNodeSets(const XsdElement::Ptr&, const Q } // copy all items from target node set to qualified node set, that have no empty fields - QSetIterator<TargetNode> it(targetNodeSet); - while (it.hasNext()) { - const TargetNode node = it.next(); + for (const TargetNode &node : qAsConst(targetNodeSet)) { if (node.emptyFieldsCount() == 0) qualifiedNodeSet.insert(node); } |