diff --git a/UPGRADING b/UPGRADING index eb158460cefb7..a3c0bdd353f5c 100644 --- a/UPGRADING +++ b/UPGRADING @@ -111,5 +111,8 @@ PHP 8.6 UPGRADE NOTES . Arguments are now passed more efficiently to known constructors (e.g. when using new self()). +- DOM: + . Made splitText() faster and consume less memory. + - JSON: . Improve performance of encoding arrays and objects. diff --git a/ext/dom/text.c b/ext/dom/text.c index ca8fcf63d3aca..1138294c8a3ea 100644 --- a/ext/dom/text.c +++ b/ext/dom/text.c @@ -129,17 +129,18 @@ PHP_METHOD(DOMText, splitText) first = xmlUTF8Strndup(cur, (int)offset); second = xmlUTF8Strsub(cur, (int)offset, (int)(length - offset)); - xmlNodeSetContent(node, first); - nnode = xmlNewDocText(node->doc, second); - - xmlFree(first); - xmlFree(second); + xmlNodeSetContent(node, NULL); + node->content = first; + nnode = xmlNewDocText(node->doc, NULL); if (nnode == NULL) { + xmlFree(second); php_dom_throw_error(INVALID_STATE_ERR, /* strict */ true); RETURN_THROWS(); } + nnode->content = second; + if (node->parent != NULL) { nnode->type = XML_ELEMENT_NODE; xmlAddNextSibling(node, nnode);