perf(core): ️ replace getElementsByTagName() with DOMCompat::querySelectorAll()

Should help with performance quite a bit
Bug: T317070
This commit is contained in:
alistair3149 2022-11-24 21:26:55 -05:00
parent b182872ea7
commit 81eadf9c8d
No known key found for this signature in database

View file

@ -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' ) {