Unifty logic in QDomNodeListPrivate::forEachNode

All iterations through QDomNodeListPrivate were going through the
forEachNode function with its own internal logic. The newly introduced
iterator works with the similar logic but is written a bit more compact.

Thus it makes sense to replace the forEachNode logic with internal
functions of the iterator.

Pick-to: 6.9
Change-Id: I22b7ae7a49e2bfaf84bede2fe0b45530a32f8d55
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Matthias Rauter 2025-01-14 14:20:55 +01:00
parent fc0e788d02
commit b1c32afb91

View File

@ -754,51 +754,13 @@ QDomNodePrivate *QDomNodeListPrivate::findPrevInOrder(QDomNodePrivate *p) const
void QDomNodeListPrivate::forEachNode(qxp::function_ref<void(QDomNodePrivate*)> yield) const
{
//TODO: simplify with findNextInList
if (!node_impl)
return;
QDomNodePrivate* p = node_impl->first;
if (tagname.isNull()) {
while (p) {
yield(p);
p = p->next;
}
} else if (nsURI.isNull()) {
while (p && p != node_impl) {
if (p->isElement() && p->nodeName() == tagname) {
yield(p);
}
if (p->first)
p = p->first;
else if (p->next)
p = p->next;
else {
p = p->parent();
while (p && p != node_impl && !p->next)
p = p->parent();
if (p && p != node_impl)
p = p->next;
}
}
} else {
while (p && p != node_impl) {
if (p->isElement() && p->name==tagname && p->namespaceURI==nsURI) {
yield(p);
}
if (p->first)
p = p->first;
else if (p->next)
p = p->next;
else {
p = p->parent();
while (p && p != node_impl && !p->next)
p = p->parent();
if (p && p != node_impl)
p = p->next;
}
}
QDomNodePrivate *current = findNextInOrder(node_impl);
while (current && current != node_impl) {
yield(current);
current = findNextInOrder(current);
}
}