Inline calls in `removeNode()` to improve the simplified-html/plain performance
authorAlexander Ebert <ebert@woltlab.com>
Mon, 12 Apr 2021 17:30:02 +0000 (19:30 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 12 Apr 2021 17:30:02 +0000 (19:30 +0200)
wcfsetup/install/files/lib/util/DOMUtil.class.php

index 238d5a1f244805d252f071cf5dbec4bee03ff3c4..f362bb93622ee4429781293fd00d1ea15949f1da 100644 (file)
@@ -478,6 +478,8 @@ final class DOMUtil {
         * @param       boolean         $preserveChildNodes     preserve child nodes, only supported for elements
         */
        public static function removeNode(\DOMNode $node, $preserveChildNodes = false) {
+               $parent = $node->parentNode ?: $node->ownerDocument;
+
                if ($preserveChildNodes) {
                        if (!($node instanceof \DOMElement)) {
                                throw new \InvalidArgumentException("Preserving child nodes is only supported for DOMElement.");
@@ -489,11 +491,11 @@ final class DOMUtil {
                        }
 
                        foreach ($children as $child) {
-                               self::insertBefore($child, $node);
+                               $parent->insertBefore($child, $node);
                        }
                }
                
-               self::getParentNode($node)->removeChild($node);
+               $parent->removeChild($node);
        }
        
        /**