From b1c32afb914a8dda0b1b38bf9d85c1c316b27cf1 Mon Sep 17 00:00:00 2001 From: Matthias Rauter Date: Tue, 14 Jan 2025 14:20:55 +0100 Subject: [PATCH] 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 --- src/xml/dom/qdom.cpp | 46 ++++---------------------------------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 8259da2f1cb..93c0f85c7c5 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -754,51 +754,13 @@ QDomNodePrivate *QDomNodeListPrivate::findPrevInOrder(QDomNodePrivate *p) const void QDomNodeListPrivate::forEachNode(qxp::function_ref 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); } }