Skip to content

Commit

Permalink
Add is_equivalent method to AFE, remove eager sort
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Aug 29, 2024
1 parent c5cc0e4 commit bbaa396
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ public function push( AFE_Element|AFE_Marker $afe ): void {
*/
$count = 0;
foreach ( $this->walk_up_until_marker() as $item ) {
if (
$item->namespace === $afe->namespace &&
$item->tag_name === $afe->tag_name &&
$item->attributes === $afe->attributes
) {
if ( $item->is_equivalent( $afe ) ) {
if ( ++$count >= 3 ) {
return;
}
Expand Down Expand Up @@ -294,6 +290,23 @@ class AFE_Element {
/** @var WP_HTML_Token */
public $token;

public function is_equivalent( self $afe ): bool {
if (
$this->namespace !== $afe->namespace ||
$this->tag_name !== $afe->tag_name ||
count( $this->attributes ) !== count( $afe->attributes )
) {
return false;
}

foreach ( $this->attributes as $name => $value ) {
if ( ! array_key_exists( $name, $afe->attributes ) || $value !== $afe->attributes[ $name ] ) {
return false;
}
}
return true;
}

public function __construct( string $tag_namespace, string $tag_name, array $attributes, WP_HTML_Token $token ) {
$this->namespace = $tag_namespace;
$this->tag_name = $tag_name;
Expand Down
1 change: 0 additions & 1 deletion src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6227,7 +6227,6 @@ private function push_active_formatting_element( WP_HTML_Token $token ) {
foreach ( $proc->get_attribute_names_with_prefix( '' ) as $name ) {
$attributes[ $name ] = $proc->get_attribute( $name );
}
sort( $attributes );
$afe = new AFE_Element(
$token->namespace,
$token->node_name,
Expand Down

0 comments on commit bbaa396

Please sign in to comment.