summaryrefslogtreecommitdiff
path: root/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-09-04 16:55:29 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-09-20 18:24:49 +0000
commit21cc71ced3565585f7a2f94875ed845355ab2064 (patch)
treefc9c632572e6f69d3753bc4a2658cec3e5cc7bff /src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h
parentb1b57225dbc8733935697e1895631969e9a95376 (diff)
downloadqtxmlpatterns-21cc71ced3565585f7a2f94875ed845355ab2064.tar.gz
Eradicate Java-style loops (I): QHashIterator -> STL-style
Java-style iterators are slower than STL-style ones, so they should not be used in library code. Replaced them with STL iterator loops. In one case, a QMutableHashIterator actually needn't be mutable, so ported to const_iterator, like all others. Change-Id: Ib7fd1fa5fca2df2c288a61925ee68a5df11caf62 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h')
-rw-r--r--src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h56
1 files changed, 18 insertions, 38 deletions
diff --git a/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h b/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h
index b989584..2583bb9 100644
--- a/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h
+++ b/src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h
@@ -74,9 +74,7 @@ typename XsdStateMachine<TransitionType>::StateId XsdStateMachine<TransitionType
#ifndef QT_NO_DEBUG
// make sure we don't have two start states
if (type == StartState) {
- QHashIterator<StateId, StateType> it(m_states);
- while (it.hasNext()) {
- it.next();
+ for (auto it = m_states.cbegin(), end = m_states.cend(); it != end; ++it) {
Q_ASSERT(it.value() != StartState && it.value() != StartEndState);
}
}
@@ -113,9 +111,7 @@ template <typename TransitionType>
void XsdStateMachine<TransitionType>::reset()
{
// reset the machine to the start state
- QHashIterator<StateId, StateType> it(m_states);
- while (it.hasNext()) {
- it.next();
+ for (auto it = m_states.cbegin(), end = m_states.cend(); it != end; ++it) {
if (it.value() == StartState || it.value() == StartEndState) {
m_currentState = it.key();
return;
@@ -179,9 +175,7 @@ bool XsdStateMachine<TransitionType>::proceed(InputType input)
// fetch the transition entry for the current state
const QHash<TransitionType, QVector<StateId> > &entry = m_transitions[m_currentState];
- QHashIterator<TransitionType, QVector<StateId> > it(entry);
- while (it.hasNext()) {
- it.next();
+ for (auto it = entry.cbegin(), end = entry.cend(); it != end; ++it) {
if (inputEqualsTransition(input, it.key())) {
m_currentState = it.value().first();
m_lastTransition = it.key();
@@ -218,9 +212,7 @@ TransitionType XsdStateMachine<TransitionType>::lastTransition() const
template <typename TransitionType>
typename XsdStateMachine<TransitionType>::StateId XsdStateMachine<TransitionType>::startState() const
{
- QHashIterator<StateId, StateType> it(m_states);
- while (it.hasNext()) {
- it.next();
+ for (auto it = m_states.cbegin(), end = m_states.cend(); it != end; ++it) {
if (it.value() == StartState || it.value() == StartEndState)
return it.key();
}
@@ -248,49 +240,39 @@ bool XsdStateMachine<TransitionType>::outputGraph(QIODevice *device, const QStri
QByteArray graph;
QTextStream s(&graph);
- QHashIterator<StateId, QHash<TransitionType, QVector<StateId> > > it(m_transitions);
- QHashIterator<StateId, StateType> it3(m_states);
-
s << "digraph " << graphName << " {\n";
s << " mindist = 2.0\n";
// draw edges
- while (it.hasNext()) {
- it.next();
+ for (auto it = m_transitions.cbegin(), end = m_transitions.cend(); it != end; ++it) {
- QHashIterator<TransitionType, QVector<StateId> > it2(it.value());
- while (it2.hasNext()) {
- it2.next();
+ for (auto it2 = it.value().cbegin(), end = it.value().cend(); it2 != end; ++it2) {
for (int i = 0; i < it2.value().count(); ++i)
s << " " << it.key() << " -> " << it2.value().at(i) << " [label=\"" << transitionTypeToString(it2.key()) << "\"]\n";
}
}
- QHashIterator<StateId, QVector<StateId> > it4(m_epsilonTransitions);
- while (it4.hasNext()) {
- it4.next();
-
- const QVector<StateId> states = it4.value();
+ for (auto it = m_epsilonTransitions.cbegin(), end = m_epsilonTransitions.cend(); it != end; ++it) {
+ const QVector<StateId> states = it.value();
for (int i = 0; i < states.count(); ++i)
- s << " " << it4.key() << " -> " << states.at(i) << " [label=\"&#949;\"]\n";
+ s << " " << it.key() << " -> " << states.at(i) << " [label=\"&#949;\"]\n";
}
// draw node info
- while (it3.hasNext()) {
- it3.next();
+ for (auto it = m_states.cbegin(), end = m_states.cend(); it != end; ++it) {
QString style;
- if (it3.value() == StartState) {
+ if (it.value() == StartState) {
style = QLatin1String("shape=circle, style=filled, color=blue");
- } else if (it3.value() == StartEndState) {
+ } else if (it.value() == StartEndState) {
style = QLatin1String("shape=doublecircle, style=filled, color=blue");
- } else if (it3.value() == InternalState) {
+ } else if (it.value() == InternalState) {
style = QLatin1String("shape=circle, style=filled, color=red");
- } else if (it3.value() == EndState) {
+ } else if (it.value() == EndState) {
style = QLatin1String("shape=doublecircle, style=filled, color=green");
}
- s << " " << it3.key() << " [" << style << "]\n";
+ s << " " << it.key() << " [" << style << "]\n";
}
s << "}\n";
@@ -357,11 +339,9 @@ XsdStateMachine<TransitionType> XsdStateMachine<TransitionType>::toDFA() const
// search the start state as the algorithm starts with it...
StateId startState = -1;
- QHashIterator<StateId, StateType> stateTypeIt(m_states);
- while (stateTypeIt.hasNext()) {
- stateTypeIt.next();
- if (stateTypeIt.value() == StartState) {
- startState = stateTypeIt.key();
+ for (auto it = m_states.cbegin(), end = m_states.cend(); it != end; ++it) {
+ if (it.value() == StartState) {
+ startState = it.key();
break;
}
}