summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/xmlpatterns/acceltree/qacceltree.cpp6
-rw-r--r--src/xmlpatterns/expr/qexpressionfactory.cpp18
-rw-r--r--src/xmlpatterns/schema/qnamespacesupport.cpp5
-rw-r--r--src/xmlpatterns/schema/qxsdfacet_p.h1
-rw-r--r--src/xmlpatterns/schema/qxsdparticlechecker.cpp27
-rw-r--r--src/xmlpatterns/schema/qxsdschemachecker.cpp16
-rw-r--r--src/xmlpatterns/schema/qxsdstatemachine_tpl_p.h56
-rw-r--r--src/xmlpatterns/schema/qxsdtypechecker.cpp6
-rw-r--r--src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp11
9 files changed, 38 insertions, 108 deletions
diff --git a/src/xmlpatterns/acceltree/qacceltree.cpp b/src/xmlpatterns/acceltree/qacceltree.cpp
index c68c3a4..1892745 100644
--- a/src/xmlpatterns/acceltree/qacceltree.cpp
+++ b/src/xmlpatterns/acceltree/qacceltree.cpp
@@ -122,11 +122,7 @@ void AccelTree::printStats(const NamePool::Ptr &np) const
pDebug() << "+---------------+-------+-------+---------------+-------+--------------+";
pDebug() << "Namespaces(" << namespaces.count() << "):";
- QHashIterator<PreNumber, QVector<QXmlName> > it(namespaces);
- while(it.hasNext())
- {
- it.next();
-
+ for (auto it = namespaces.cbegin(), end = namespaces.cend(); it != end; ++it) {
pDebug() << "PreNumber: " << QString::number(it.key());
for(int i = 0; i < it.value().count(); ++i)
pDebug() << "\t\t" << np->stringForPrefix(it.value().at(i).prefix()) << " = " << np->stringForNamespace(it.value().at(i).namespaceURI());
diff --git a/src/xmlpatterns/expr/qexpressionfactory.cpp b/src/xmlpatterns/expr/qexpressionfactory.cpp
index f205def..b0e43be 100644
--- a/src/xmlpatterns/expr/qexpressionfactory.cpp
+++ b/src/xmlpatterns/expr/qexpressionfactory.cpp
@@ -279,11 +279,7 @@ Expression::Ptr ExpressionFactory::createExpression(const Tokenizer::Ptr &tokeni
{
pDebug() << "Have " << info->namedTemplates.count() << "named templates";
- QMutableHashIterator<QXmlName, Template::Ptr> it(info->namedTemplates);
-
- while(it.hasNext())
- {
- it.next();
+ for (auto it = info->namedTemplates.cbegin(), end = info->namedTemplates.cend(); it != end; ++it) {
processNamedTemplate(it.key(), it.value()->body, TemplateInitial);
it.value()->body = it.value()->body->typeCheck(context, CommonSequenceTypes::ZeroOrMoreItems);
@@ -298,7 +294,6 @@ Expression::Ptr ExpressionFactory::createExpression(const Tokenizer::Ptr &tokeni
/* Type check and compress template rules. */
{
- QHashIterator<QXmlName, TemplateMode::Ptr> it(info->templateRules);
/* Since a pattern can exist of AxisStep, its typeCheck() stage
* requires a focus. In the case that we're invoked with a name but
@@ -313,9 +308,7 @@ Expression::Ptr ExpressionFactory::createExpression(const Tokenizer::Ptr &tokeni
patternContext = StaticContext::Ptr(new StaticFocusContext(BuiltinTypes::node, context));
/* For each template pattern. */
- while(it.hasNext())
- {
- it.next();
+ for (auto it = info->templateRules.cbegin(), end = info->templateRules.cend(); it != end; ++it) {
const TemplateMode::Ptr &mode = it.value();
const int len = mode->templatePatterns.count();
TemplatePattern::ID currentTemplateID = -1;
@@ -387,12 +380,7 @@ Expression::Ptr ExpressionFactory::createExpression(const Tokenizer::Ptr &tokeni
Q_ASSERT_X(modeAll, Q_FUNC_INFO,
"We should at least have the builtin templates.");
- QHashIterator<QXmlName, TemplateMode::Ptr> it(info->templateRules);
-
- while(it.hasNext())
- {
- it.next();
-
+ for (auto it = info->templateRules.cbegin(), end = info->templateRules.cend(); it != end; ++it) {
/* Don't add mode #all to mode #all. */
if(it.key() == nameModeAll)
continue;
diff --git a/src/xmlpatterns/schema/qnamespacesupport.cpp b/src/xmlpatterns/schema/qnamespacesupport.cpp
index 758f6d5..846551b 100644
--- a/src/xmlpatterns/schema/qnamespacesupport.cpp
+++ b/src/xmlpatterns/schema/qnamespacesupport.cpp
@@ -146,11 +146,8 @@ QList<QXmlName> NamespaceSupport::namespaceBindings() const
{
QList<QXmlName> bindings;
- QHashIterator<QXmlName::PrefixCode, QXmlName::NamespaceCode> it(m_ns);
- while (it.hasNext()) {
- it.next();
+ for (auto it = m_ns.cbegin(), end = m_ns.cend(); it != end; ++it)
bindings.append(QXmlName(it.value(), StandardLocalNames::empty, it.key()));
- }
return bindings;
}
diff --git a/src/xmlpatterns/schema/qxsdfacet_p.h b/src/xmlpatterns/schema/qxsdfacet_p.h
index 8dd7d5f..76919d1 100644
--- a/src/xmlpatterns/schema/qxsdfacet_p.h
+++ b/src/xmlpatterns/schema/qxsdfacet_p.h
@@ -112,7 +112,6 @@ namespace QPatternist
Assertion = 1 << 12, ///< Match an assertion (<a href="http://www.w3.org/TR/xmlschema-2/#rf-assertion">Assertion Definition</a>)
};
typedef QHash<XsdFacet::Type, XsdFacet::Ptr> Hash;
- typedef QHashIterator<XsdFacet::Type, XsdFacet::Ptr> HashIterator;
/**
* Creates a new facet object of type None.
diff --git a/src/xmlpatterns/schema/qxsdparticlechecker.cpp b/src/xmlpatterns/schema/qxsdparticlechecker.cpp
index 59fc111..139390d 100644
--- a/src/xmlpatterns/schema/qxsdparticlechecker.cpp
+++ b/src/xmlpatterns/schema/qxsdparticlechecker.cpp
@@ -392,25 +392,17 @@ bool XsdParticleChecker::isUPAConform(const XsdParticle::Ptr &particle, const Na
// the basic idea of that algorithm is to iterate over all states of that machine and check that no two edges
// that match on the same term leave a state, so for a given term it should always be obvious which edge to take
- QHashIterator<XsdStateMachine<XsdTerm::Ptr>::StateId, XsdStateMachine<XsdTerm::Ptr>::StateType> stateIt(states);
- while (stateIt.hasNext()) { // iterate over all states
- stateIt.next();
-
+ for (auto stateIt = states.cbegin(), end = states.cend(); stateIt != end; ++stateIt) {
// fetch all transitions the current state allows
const QHash<XsdTerm::Ptr, QVector<XsdStateMachine<XsdTerm::Ptr>::StateId> > currentTransitions = transitions.value(stateIt.key());
- QHashIterator<XsdTerm::Ptr, QVector<XsdStateMachine<XsdTerm::Ptr>::StateId> > transitionIt(currentTransitions);
- while (transitionIt.hasNext()) { // iterate over all transitions
- transitionIt.next();
-
+ for (auto transitionIt = currentTransitions.cbegin(), end = currentTransitions.cend(); transitionIt != end; ++transitionIt) {
if (transitionIt.value().size() > 1) {
// we have one state with two edges leaving it, that means
// the XsdTerm::Ptr exists twice, that is an error
return false;
}
- QHashIterator<XsdTerm::Ptr, QVector<XsdStateMachine<XsdTerm::Ptr>::StateId> > innerTransitionIt(currentTransitions);
- while (innerTransitionIt.hasNext()) { // iterate over all transitions again, as we have to compare all transitions with all
- innerTransitionIt.next();
+ for (auto innerTransitionIt = currentTransitions.cbegin(), end = currentTransitions.cend(); innerTransitionIt != end; ++innerTransitionIt) {
if (transitionIt.key() == innerTransitionIt.key()) // do no compare with ourself
continue;
@@ -516,17 +508,13 @@ bool XsdParticleChecker::subsumes(const XsdParticle::Ptr &particle, const XsdPar
const QPair<XsdStateMachine<XsdTerm::Ptr>::StateId, XsdStateMachine<XsdTerm::Ptr>::StateId> set = workSet.takeFirst();
const QHash<XsdTerm::Ptr, QVector<XsdStateMachine<XsdTerm::Ptr>::StateId> > derivedTrans = derivedTransitions.value(set.second);
- QHashIterator<XsdTerm::Ptr, QVector<XsdStateMachine<XsdTerm::Ptr>::StateId> > derivedIt(derivedTrans);
const QHash<XsdTerm::Ptr, QVector<XsdStateMachine<XsdTerm::Ptr>::StateId> > baseTrans = baseTransitions.value(set.first);
- while (derivedIt.hasNext()) {
- derivedIt.next();
+ for (auto derivedIt = derivedTrans.cbegin(), end = derivedTrans.cend(); derivedIt != end; ++derivedIt) {
bool found = false;
- QHashIterator<XsdTerm::Ptr, QVector<XsdStateMachine<XsdTerm::Ptr>::StateId> > baseIt(baseTrans);
- while (baseIt.hasNext()) {
- baseIt.next();
+ for (auto baseIt = baseTrans.cbegin(), end = baseTrans.cend(); baseIt != end; ++baseIt) {
if (derivedTermValid(baseIt.key(), derivedIt.key(), particlesHash, context, errorMsg)) {
const QPair<XsdStateMachine<XsdTerm::Ptr>::StateId, XsdStateMachine<XsdTerm::Ptr>::StateId> endSet =
qMakePair<XsdStateMachine<XsdTerm::Ptr>::StateId, XsdStateMachine<XsdTerm::Ptr>::StateId>(baseIt.value().first(), derivedIt.value().first());
@@ -546,10 +534,7 @@ bool XsdParticleChecker::subsumes(const XsdParticle::Ptr &particle, const XsdPar
}
// 5)
- QHashIterator<XsdStateMachine<XsdTerm::Ptr>::StateId, XsdStateMachine<XsdTerm::Ptr>::StateType> it(derivedStates);
- while (it.hasNext()) {
- it.next();
-
+ for (auto it = derivedStates.cbegin(), end = derivedStates.cend(); it != end; ++it) {
if (it.value() == XsdStateMachine<XsdTerm::Ptr>::EndState || it.value() == XsdStateMachine<XsdTerm::Ptr>::StartEndState) {
for (int i = 0; i < processedSet.count(); ++i) {
if (processedSet.at(i).second == it.key() &&
diff --git a/src/xmlpatterns/schema/qxsdschemachecker.cpp b/src/xmlpatterns/schema/qxsdschemachecker.cpp
index 0898848..5e4302d 100644
--- a/src/xmlpatterns/schema/qxsdschemachecker.cpp
+++ b/src/xmlpatterns/schema/qxsdschemachecker.cpp
@@ -436,11 +436,9 @@ void XsdSchemaChecker::checkSimpleTypeConstraints()
// 2.2.1.2
const XsdFacet::Hash facets = simpleType->facets();
- XsdFacet::HashIterator it(facets);
bool invalidFacetFound = false;
- while (it.hasNext()) {
- it.next();
+ for (auto it = facets.cbegin(), end = facets.cend(); it != end; ++it) {
if (it.key() != XsdFacet::WhiteSpace) {
invalidFacetFound = true;
break;
@@ -476,12 +474,10 @@ void XsdSchemaChecker::checkSimpleTypeConstraints()
// 2.2.2.4
const XsdFacet::Hash facets = simpleType->facets();
- XsdFacet::HashIterator it(facets);
bool invalidFacetFound = false;
XsdFacet::Type invalidFacetType = XsdFacet::None;
- while (it.hasNext()) {
- it.next();
+ for (auto it = facets.cbegin(), end = facets.cend(); it != end; ++it) {
const XsdFacet::Type facetType = it.key();
if (facetType != XsdFacet::Length &&
facetType != XsdFacet::MinimumLength &&
@@ -573,12 +569,10 @@ void XsdSchemaChecker::checkSimpleTypeConstraints()
// 3.1.2.4
const XsdFacet::Hash facets = simpleType->facets();
- XsdFacet::HashIterator it(facets);
bool invalidFacetFound = false;
XsdFacet::Type invalidFacetType = XsdFacet::None;
- while (it.hasNext()) {
- it.next();
+ for (auto it = facets.cbegin(), end = facets.cend(); it != end; ++it) {
const XsdFacet::Type facetType = it.key();
if (facetType != XsdFacet::Pattern &&
facetType != XsdFacet::Enumeration) {
@@ -1573,9 +1567,7 @@ void XsdSchemaChecker::checkConstrainingFacets(const XsdFacet::Hash &facets, con
if (!baseType->isDefinedBySchema()) {
const XsdSchemaSourceLocationReflection reflection(sourceLocation(simpleType));
- XsdFacet::HashIterator it(facets);
- while (it.hasNext()) {
- it.next();
+ for (auto it = facets.cbegin(), end = facets.cend(); it != end; ++it) {
const XsdFacet::Ptr facet = it.value();
if (facet->type() == XsdFacet::MaximumInclusive ||
facet->type() == XsdFacet::MaximumExclusive ||
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;
}
}
diff --git a/src/xmlpatterns/schema/qxsdtypechecker.cpp b/src/xmlpatterns/schema/qxsdtypechecker.cpp
index 7c554c5..2e4ce8e 100644
--- a/src/xmlpatterns/schema/qxsdtypechecker.cpp
+++ b/src/xmlpatterns/schema/qxsdtypechecker.cpp
@@ -206,12 +206,8 @@ XsdFacet::Hash XsdTypeChecker::mergedFacetsForType(const SchemaType::Ptr &type,
const XsdFacet::Hash facets = context->facetsForType(type);
XsdFacet::Hash result = baseFacets;
- XsdFacet::HashIterator it(facets);
- while (it.hasNext()) {
- it.next();
-
+ for (auto it = facets.cbegin(), end = facets.cend(); it != end; ++it)
result.insert(it.key(), it.value());
- }
return result;
}
diff --git a/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp b/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp
index bf33af1..7e60667 100644
--- a/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp
+++ b/src/xmlpatterns/schema/qxsdvalidatinginstancereader.cpp
@@ -732,14 +732,11 @@ bool XsdValidatingInstanceReader::validateElementComplexType(const XsdElement::P
const QSet<QXmlName> attributes(attributeNames());
// 3
- QHashIterator<QXmlName, XsdAttributeUse::Ptr> usesIt(attributeUseHash);
- while (usesIt.hasNext()) {
- usesIt.next();
-
- if (usesIt.value()->isRequired()) {
- if (!attributes.contains(usesIt.key())) {
+ for (auto it = attributeUseHash.cbegin(), end = attributeUseHash.cend(); it != end; ++it) {
+ if (it.value()->isRequired()) {
+ if (!attributes.contains(it.key())) {
error(QtXmlPatterns::tr("Element %1 is missing required attribute %2.").arg(formatKeyword(declaration->displayName(m_namePool)))
- .arg(formatKeyword(m_namePool->displayName(usesIt.key()))));
+ .arg(formatKeyword(m_namePool->displayName(it.key()))));
return false;
}
}