From 76f66297178f7f7630a7655bfe2f99b052423f49 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 12 Apr 2021 21:42:29 +0200 Subject: [PATCH] `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("//*")` --- .../lib/system/html/node/AbstractHtmlNodeProcessor.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } -- 2.20.1