Skip to content

Commit a96fcac

Browse files
committed
HTML API: Pass boolean is_pop to stack event constructor
Replace string-based operation parameter with a boolean is_pop flag passed directly from the call sites. Eliminates a string comparison in the constructor for every stack event (~1.5M per benchmark run).
1 parent f86c69a commit a96fcac

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ function ( WP_HTML_Token $token ): void {
459459
$current_token = $this->state->current_token;
460460
$is_virtual = ! isset( $current_token ) || parent::is_tag_closer();
461461
$provenance = ( ! $is_virtual && $token->node_name === $current_token->node_name ) ? 'real' : 'virtual';
462-
$this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::PUSH, $provenance );
462+
$this->element_queue[] = new WP_HTML_Stack_Event( $token, false, $provenance );
463463

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class WP_HTML_Stack_Event {
8383
* @param string $operation One of self::PUSH or self::POP.
8484
* @param string $provenance "virtual" or "real".
8585
*/
86-
public function __construct( WP_HTML_Token $token, string $operation, string $provenance ) {
86+
public function __construct( WP_HTML_Token $token, bool $is_pop, string $provenance ) {
8787
$this->token = $token;
8888
$this->provenance = $provenance;
89-
$this->is_pop = self::POP === $operation;
89+
$this->is_pop = $is_pop;
9090
}
9191
}

0 commit comments

Comments
 (0)