Skip to content

Commit b1c32af

Browse files
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 <[email protected]>
1 parent fc0e788 commit b1c32af

File tree

1 file changed

+4
-42
lines changed

1 file changed

+4
-42
lines changed

src/xml/dom/qdom.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -754,51 +754,13 @@ QDomNodePrivate *QDomNodeListPrivate::findPrevInOrder(QDomNodePrivate *p) const
754754

755755
void QDomNodeListPrivate::forEachNode(qxp::function_ref<void(QDomNodePrivate*)> yield) const
756756
{
757-
//TODO: simplify with findNextInList
758757
if (!node_impl)
759758
return;
760759

761-
QDomNodePrivate* p = node_impl->first;
762-
763-
if (tagname.isNull()) {
764-
while (p) {
765-
yield(p);
766-
p = p->next;
767-
}
768-
} else if (nsURI.isNull()) {
769-
while (p && p != node_impl) {
770-
if (p->isElement() && p->nodeName() == tagname) {
771-
yield(p);
772-
}
773-
if (p->first)
774-
p = p->first;
775-
else if (p->next)
776-
p = p->next;
777-
else {
778-
p = p->parent();
779-
while (p && p != node_impl && !p->next)
780-
p = p->parent();
781-
if (p && p != node_impl)
782-
p = p->next;
783-
}
784-
}
785-
} else {
786-
while (p && p != node_impl) {
787-
if (p->isElement() && p->name==tagname && p->namespaceURI==nsURI) {
788-
yield(p);
789-
}
790-
if (p->first)
791-
p = p->first;
792-
else if (p->next)
793-
p = p->next;
794-
else {
795-
p = p->parent();
796-
while (p && p != node_impl && !p->next)
797-
p = p->parent();
798-
if (p && p != node_impl)
799-
p = p->next;
800-
}
801-
}
760+
QDomNodePrivate *current = findNextInOrder(node_impl);
761+
while (current && current != node_impl) {
762+
yield(current);
763+
current = findNextInOrder(current);
802764
}
803765
}
804766

0 commit comments

Comments
 (0)