From 81eadf9c8d1651691033e088922037b60239fb7a Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 24 Nov 2022 21:26:55 -0500 Subject: [PATCH] =?UTF-8?q?perf(core):=20=E2=9A=A1=EF=B8=8F=20replace=20ge?= =?UTF-8?q?tElementsByTagName()=20with=20DOMCompat::querySelectorAll()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should help with performance quite a bit Bug: T317070 --- includes/Partials/BodyContent.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/Partials/BodyContent.php b/includes/Partials/BodyContent.php index 05a117b5..e61a09b0 100644 --- a/includes/Partials/BodyContent.php +++ b/includes/Partials/BodyContent.php @@ -31,6 +31,7 @@ use DOMXpath; use Html; use HtmlFormatter\HtmlFormatter; use MediaWiki\MediaWikiServices; +use Wikimedia\Parsoid\Utils\DOMCompat; use Wikimedia\Services\NoSuchServiceException; final class BodyContent extends Partial { @@ -206,7 +207,7 @@ final class BodyContent extends Partial { $headings = []; foreach ( $this->topHeadingTags as $tagName ) { - $allTags = $doc->getElementsByTagName( $tagName ); + $allTags = DOMCompat::querySelectorAll( $doc, $tagName ); foreach ( $allTags as $el ) { if ( $el->parentNode->getAttribute( 'class' ) !== 'toctitle' ) { @@ -251,7 +252,7 @@ final class BodyContent extends Partial { $found = false; $subheadings = []; foreach ( $this->topHeadingTags as $tagName ) { - $allTags = $doc->getElementsByTagName( $tagName ); + $allTags = DOMCompat::querySelectorAll( $doc, $tagName ); $elements = []; foreach ( $allTags as $el ) { if ( $el->parentNode->getAttribute( 'class' ) !== 'toctitle' ) {