From: Alexander Ebert Date: Mon, 12 Apr 2021 19:42:29 +0000 (+0200) Subject: `XPath::query()` is much more efficient than `getElementByTagName()` X-Git-Tag: 5.3.6~9^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=76f66297178f7f7630a7655bfe2f99b052423f49;p=GitHub%2FWoltLab%2FWCF.git `XPath::query()` is much more efficient than `getElementByTagName()` The test document with ~8k elements took ~0.6s using `getElementsByTagName(*)`, but only 0.03s using `query("//*")` --- diff --git a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php index f3fdfe0f3c..6e4cf72229 100644 --- a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php @@ -304,7 +304,7 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor { $tags = []; /** @var \DOMElement $tag */ - foreach ($this->getDocument()->getElementsByTagName('*') as $tag) { + foreach ($this->getXPath()->query("//*") as $tag) { $tagName = $tag->nodeName; if (!isset($tags[$tagName])) $tags[$tagName] = $tagName; }