Skip to content

Commit 7942a0c

Browse files
committed
Add is_equivalent method to AFE, remove eager sort
1 parent 096e5d0 commit 7942a0c

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/wp-includes/html-api/class-wp-html-active-formatting-elements.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ public function push( AFE_Element|AFE_Marker $afe ): void {
144144
*/
145145
$count = 0;
146146
foreach ( $this->walk_up_until_marker() as $item ) {
147-
if (
148-
$item->namespace === $afe->namespace &&
149-
$item->tag_name === $afe->tag_name &&
150-
$item->attributes === $afe->attributes
151-
) {
147+
if ( $item->is_equivalent( $afe ) ) {
152148
if ( ++$count >= 3 ) {
153149
return;
154150
}
@@ -294,6 +290,23 @@ class AFE_Element {
294290
/** @var WP_HTML_Token */
295291
public $token;
296292

293+
public function is_equivalent( self $afe ): bool {
294+
if (
295+
$this->namespace !== $afe->namespace ||
296+
$this->tag_name !== $afe->tag_name ||
297+
count( $this->attributes ) !== count( $afe->attributes )
298+
) {
299+
return false;
300+
}
301+
302+
foreach ( $this->attributes as $name => $value ) {
303+
if ( ! array_key_exists( $name, $afe->attributes ) || $value !== $afe->attributes[ $name ] ) {
304+
return false;
305+
}
306+
}
307+
return true;
308+
}
309+
297310
public function __construct( string $tag_namespace, string $tag_name, array $attributes, WP_HTML_Token $token ) {
298311
$this->namespace = $tag_namespace;
299312
$this->tag_name = $tag_name;

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6227,7 +6227,6 @@ private function push_active_formatting_element( WP_HTML_Token $token ) {
62276227
foreach ( $proc->get_attribute_names_with_prefix( '' ) as $name ) {
62286228
$attributes[ $name ] = $proc->get_attribute( $name );
62296229
}
6230-
sort( $attributes );
62316230
$afe = new AFE_Element(
62326231
$token->namespace,
62336232
$token->node_name,

0 commit comments

Comments
 (0)