Skip to content

Commit 92c0db3

Browse files
authored
Avoid reconciling when cloning into the same document (#14921)
We don't need to reconcile when we clone into the same document because the namespace mapper is the same. Only when cloning into another document is the namespace mapper different and do we need a reconciliation.
1 parent e935f00 commit 92c0db3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ext/dom/php_dom.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,9 @@ xmlNodePtr dom_clone_node(php_dom_libxml_ns_mapper *ns_mapper, xmlNodePtr node,
25672567

25682568
if (ns_mapper != NULL) {
25692569
xmlNodePtr clone = dom_clone_helper(ns_mapper, node, doc, recursive);
2570-
if (EXPECTED(clone != NULL)) {
2570+
if (EXPECTED(clone != NULL) && doc != node->doc) {
2571+
/* We only need to reconcile the namespace when the document changes because the namespaces have to be
2572+
* put into their respective namespace mapper. */
25712573
if (clone->type == XML_DOCUMENT_NODE || clone->type == XML_HTML_DOCUMENT_NODE || clone->type == XML_DOCUMENT_FRAG_NODE) {
25722574
for (xmlNodePtr child = clone->children; child != NULL; child = child->next) {
25732575
php_dom_libxml_reconcile_modern(ns_mapper, child);

0 commit comments

Comments
 (0)