Skip to content

Commit 43dcb78

Browse files
committed
HTML API: Replace provenance string with is_virtual boolean on stack events
Replace the 'virtual'/'real' provenance string with a boolean is_virtual flag. This eliminates string allocation and comparison, replacing them with a direct boolean assignment and check.
1 parent 3a35fe3 commit 43dcb78

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ public function __construct( $html, $use_the_static_create_methods_instead = nul
458458
function ( WP_HTML_Token $token ): void {
459459
$current_token = $this->state->current_token;
460460
$is_virtual = ! isset( $current_token ) || parent::is_tag_closer();
461-
$provenance = ( ! $is_virtual && $token->node_name === $current_token->node_name ) ? 'real' : 'virtual';
462-
$this->element_queue[] = new WP_HTML_Stack_Event( $token, false, $provenance );
461+
$is_virtual_event = $is_virtual || $token->node_name !== $current_token->node_name;
462+
$this->element_queue[] = new WP_HTML_Stack_Event( $token, false, $is_virtual_event );
463463

464464
if ( $token->integration_node_type ) {
465465
$this->change_parsing_namespace( 'html' );
@@ -473,8 +473,8 @@ function ( WP_HTML_Token $token ): void {
473473
function ( WP_HTML_Token $token ): void {
474474
$current_token = $this->state->current_token;
475475
$is_virtual = ! isset( $current_token ) || ! parent::is_tag_closer();
476-
$provenance = ( ! $is_virtual && $token->node_name === $current_token->node_name ) ? 'real' : 'virtual';
477-
$this->element_queue[] = new WP_HTML_Stack_Event( $token, true, $provenance );
476+
$is_virtual_event = $is_virtual || $token->node_name !== $current_token->node_name;
477+
$this->element_queue[] = new WP_HTML_Stack_Event( $token, true, $is_virtual_event );
478478

479479
$adjusted_current_node = $this->get_adjusted_current_node();
480480

@@ -968,10 +968,7 @@ public function is_tag_closer(): bool {
968968
* @return bool Whether the current token is virtual.
969969
*/
970970
private function is_virtual(): bool {
971-
return (
972-
isset( $this->current_element->provenance ) &&
973-
'virtual' === $this->current_element->provenance
974-
);
971+
return isset( $this->current_element ) && $this->current_element->is_virtual;
975972
}
976973

977974
/**

src/wp-includes/html-api/class-wp-html-stack-event.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,32 @@ class WP_HTML_Stack_Event {
6565
*
6666
* @var string
6767
*/
68-
public $provenance;
69-
7068
/**
7169
* Whether this event is a pop operation.
7270
*
7371
* @var bool
7472
*/
7573
public $is_pop;
7674

75+
/**
76+
* Whether this event is for a virtual (implied) node.
77+
*
78+
* @var bool
79+
*/
80+
public $is_virtual;
81+
7782
/**
7883
* Constructor function.
7984
*
8085
* @since 6.6.0
8186
*
8287
* @param WP_HTML_Token $token Token associated with stack event, always an opening token.
83-
* @param string $operation One of self::PUSH or self::POP.
84-
* @param string $provenance "virtual" or "real".
88+
* @param bool $is_pop Whether this is a pop event.
89+
* @param bool $is_virtual Whether this is a virtual event.
8590
*/
86-
public function __construct( WP_HTML_Token $token, bool $is_pop, string $provenance ) {
91+
public function __construct( WP_HTML_Token $token, bool $is_pop, bool $is_virtual ) {
8792
$this->token = $token;
88-
$this->provenance = $provenance;
8993
$this->is_pop = $is_pop;
94+
$this->is_virtual = $is_virtual;
9095
}
9196
}

0 commit comments

Comments
 (0)