wppaste
WordPress

WP_HTML_Processor::step_in_table(): bool

Since
6.7.0
Source
wp-includes/html-api/class-wp-html-processor.php:3441
Parses next element in the 'in table' insertion mode.

Description

This internal function performs the 'in table' insertion mode logic for the generalized WP_HTML_Processor::step() function.

Compatibility

WordPress
since 6.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

bool
Whether an element was found.

Performance profile

How much work a call to WP_HTML_Processor::step_in_table() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
16–111

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 330.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 38 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::step_in_table() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$token_type !== "#tag"16–72->get_token_name(), ->get_token_type(), ->step()
$token_type !== "#tag"16–80->get_token_name(), ->get_token_type(), ->step_in_head()
$token_type !== "#tag"17–86->get_token_name(), ->get_token_type(), ->bail()
$token_type !== "#tag"19–29->get_token_name(), ->get_token_type(), ->insert_html_element()
$token_type === "#tag"21–78->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->step()
$token_type === "#tag"21–86->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->step_in_head()
$token_type !== "#tag" && !->has_element_in_table_scope()22–56->get_token_name(), ->get_token_type(), ->has_element_in_table_scope(), ->step()
$token_type !== "#tag"22–93->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->step()
$token_type === "#tag"22–92->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->bail()
$token_type !== "#tag" && !is_string($type_attribute)23–89->get_token_name(), ->get_token_type(), ->get_attribute(), ->bail()
$token_type === "#tag"24–35->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->insert_html_element()
$token_type !== "#tag"26–41->get_token_name(), ->get_token_type(), ->current_node(), ->bail()
26 further outcomes, up to 59 instructions
$token_type !== "#tag" && ->has_element_in_table_scope()26–60->get_token_name(), ->get_token_type(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately()
$token_type !== "#tag"27–51->get_token_name(), ->get_token_type(), ->clear_to_table_context(), ->insert_html_element()
$token_type === "#tag" && !->has_element_in_table_scope()27–62->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_table_scope(), ->step()
$token_type === "#tag"27–99->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_scope(), ->step()
$token_type !== "#tag" && is_string($type_attribute)28–94->get_token_name(), ->get_token_type(), ->get_attribute(), strtolower(), ->bail()
$token_type === "#tag" && !is_string($type_attribute)28–95->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->get_attribute(), ->bail()
$token_type !== "#tag"29–59->get_token_name(), ->get_token_type(), ->clear_to_table_context(), ->insert_virtual_node(), ->step()
$token_type !== "#tag" && is_string($type_attribute)30–96->get_token_name(), ->get_token_type(), ->get_attribute(), strtolower(), ->insert_html_element()
$token_type !== "#tag"31–44->get_token_name(), ->get_token_type(), ->current_node(), ->step()
$token_type !== "#tag"31–45->get_token_name(), ->get_token_type(), ->clear_to_table_context(), ->insert_marker(), ->insert_html_element()
$token_type === "#tag"31–47->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->bail()
$token_type !== "#tag" && ->has_element_in_table_scope()31–63->get_token_name(), ->get_token_type(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately(), ->step()
$token_type === "#tag" && ->has_element_in_table_scope()31–66->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately()
$token_type === "#tag"32–57->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->clear_to_table_context(), ->insert_html_element()
$token_type === "#tag" && is_string($type_attribute)33–100->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->get_attribute(), strtolower(), ->bail()
$token_type === "#tag"34–65->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->clear_to_table_context(), ->insert_virtual_node(), ->step()
$token_type === "#tag" && is_string($type_attribute)35–102->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->get_attribute(), strtolower(), ->insert_html_element()
$token_type === "#tag"36–50->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->step()
$token_type === "#tag"36–51->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->clear_to_table_context(), ->insert_marker(), ->insert_html_element()
$token_type === "#tag" && ->has_element_in_table_scope()36–69->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_table_scope(), ->pop_until(), ->reset_insertion_mode_appropriately(), ->step()
$token_type !== "#tag" && !->has_element_in_scope() && !isset($value)37–105->get_token_name(), ->get_token_type(), ->has_element_in_scope(), ->insert_html_element(), ->pop()
$token_type !== "#tag"38–51->get_token_name(), ->get_token_type(), ->current_node(), ->insert_html_element()
$token_type !== "#tag"40–53->get_token_name(), ->get_token_type(), ->current_node(), ->bail(), ->bail()
$token_type === "#tag" && !->has_element_in_scope() && !isset($value)42–111->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->has_element_in_scope(), ->insert_html_element(), ->pop()
$token_type === "#tag"43–57->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->insert_html_element()
$token_type === "#tag"45–59->get_token_name(), ->get_token_type(), ::is_tag_closer(), ->current_node(), ->bail(), ->bail()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev33016–11153
8.533016–11153
8.433016–11153
8.333016–11153
8.233016–111531 more instruction than PHP 8.1
8.132916–125531 fewer instruction than PHP 7.4
7.433016–12653

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 10

Used by · 4

Source code

	private function step_in_table(): bool {		$token_name = $this->get_token_name();		$token_type = $this->get_token_type();		$op_sigil   = '#tag' === $token_type ? ( parent::is_tag_closer() ? '-' : '+' ) : '';		$op         = "{$op_sigil}{$token_name}"; 		switch ( $op ) {			/*			 * > A character token, if the current node is table,			 * > tbody, template, tfoot, thead, or tr element			 */			case '#text':				$current_node      = $this->state->stack_of_open_elements->current_node();				$current_node_name = $current_node ? $current_node->node_name : null;				if (					$current_node_name && (						'TABLE' === $current_node_name ||						'TBODY' === $current_node_name ||						'TEMPLATE' === $current_node_name ||						'TFOOT' === $current_node_name ||						'THEAD' === $current_node_name ||						'TR' === $current_node_name					)				) {					/*					 * If the text is empty after processing HTML entities and stripping					 * U+0000 NULL bytes then ignore the token.					 */					if ( parent::TEXT_IS_NULL_SEQUENCE === $this->text_node_classification ) {						return $this->step();					} 					/*					 * This follows the rules for "in table text" insertion mode.					 *					 * Whitespace-only text nodes are inserted in-place. Otherwise					 * foster parenting is enabled and the nodes would be					 * inserted out-of-place.					 *					 * > If any of the tokens in the pending table character tokens					 * > list are character tokens that are not ASCII whitespace,					 * > then this is a parse error: reprocess the character tokens					 * > in the pending table character tokens list using the rules					 * > given in the "anything else" entry in the "in table"					 * > insertion mode.					 * >					 * > Otherwise, insert the characters given by the pending table					 * > character tokens list.					 *					 * @see https://html.spec.whatwg.org/#parsing-main-intabletext					 */					if ( parent::TEXT_IS_WHITESPACE === $this->text_node_classification ) {						$this->insert_html_element( $this->state->current_token );						return true;					} 					// Non-whitespace would trigger fostering, unsupported at this time.					$this->bail( 'Foster parenting is not supported.' );					break;				}				break; 			/*			 * > A comment token			 * > A processing instruction token			 */			case '#comment':			case '#funky-comment':			case '#presumptuous-tag':			case '#processing-instruction':				$this->insert_html_element( $this->state->current_token );				return true; 			/*			 * > A DOCTYPE token			 */			case 'html':				// Parse error: ignore the token.				return $this->step();

Changelog

Introduced in 6.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/html-api/class-wp-html-processor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.