WP_HTML_Processor::run_adoption_agency_algorithm()
- Since
- 6.4.0
- Source
wp-includes/html-api/class-wp-html-processor.php:6102
Compatibility
- WordPress
- since 6.4.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.
Performance profile
How much work a call to WP_HTML_Processor::run_adoption_agency_algorithm() 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
- Light
- Scaling
- Scales with input
- Instructions
- 19–104
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 127.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_HTML_Processor::run_adoption_agency_algorithm() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$budget | 19–22 | ->get_tag(), ->current_node() |
!$budget | 19–22 | ->get_tag(), ->current_node(), ->bail() |
$subject === false && !->contains_node() | 24 | ->get_tag(), ->current_node(), ->contains_node(), ->pop() |
$subject === false && ->contains_node() && $budget | 28 | ->get_tag(), ->current_node(), ->contains_node() |
$subject === false && ->contains_node() && !$budget | 28 | ->get_tag(), ->current_node(), ->contains_node(), ->bail() |
$budget && $formatting_element !== null && !->contains_node() | 39–50 | ->get_tag(), ->current_node(), ->walk_up(), ->contains_node(), ->remove_node() |
$budget && $formatting_element !== null && ->contains_node() && !->has_element_in_scope() | 42–53 | ->get_tag(), ->current_node(), ->walk_up(), ->contains_node(), ->has_element_in_scope() |
$budget && $formatting_element === null && !->contains_node() | 42–53 | ->get_tag(), ->current_node(), ->walk_up(), ->bail(), ->contains_node(), ->remove_node() |
$budget && $formatting_element === null && ->contains_node() && !->has_element_in_scope() | 45–56 | ->get_tag(), ->current_node(), ->walk_up(), ->bail(), ->contains_node(), ->has_element_in_scope() |
$subject === false && $budget && $formatting_element !== null | 48–56 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->contains_node(), ->remove_node() |
$subject === false && ->contains_node() && $budget && $formatting_element !== null && !->has_element_in_scope() | 51–59 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->contains_node(), ->has_element_in_scope() |
$subject === false && $budget && $formatting_element === null | 51–59 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->bail(), ->contains_node(), ->remove_node() |
9 further outcomes, up to 104 instructions
$subject === false && ->contains_node() && $budget && $formatting_element === null && !->has_element_in_scope() | 54–62 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->bail(), ->contains_node(), ->has_element_in_scope() |
$budget && $formatting_element !== null && ->contains_node() && ->has_element_in_scope() && $furthest_block === null && !->walk_up() | 72–84 | ->get_tag(), ->current_node(), ->walk_up(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ->walk_up(), ->pop(), ->remove_node() |
$budget && $formatting_element === null && ->contains_node() && ->has_element_in_scope() && $furthest_block === null && !->walk_up() | 75–87 | ->get_tag(), ->current_node(), ->walk_up(), ->bail(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ->walk_up(), ->pop(), ->remove_node() |
$budget && $formatting_element !== null && ->contains_node() && ->has_element_in_scope() && !->walk_down() && ::is_special() && $furthest_block === null && !->walk_up() | 79–95 | ->get_tag(), ->current_node(), ->walk_up(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ::is_special(), ->walk_up(), ->pop(), ->remove_node() |
$subject === false && ->contains_node() && $budget && $formatting_element !== null && ->has_element_in_scope() && $furthest_block === null && !->walk_up() | 81–90 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ->walk_up(), ->pop(), ->remove_node() |
$budget && $formatting_element === null && ->contains_node() && ->has_element_in_scope() && !->walk_down() && ::is_special() && $furthest_block === null && !->walk_up() | 82–98 | ->get_tag(), ->current_node(), ->walk_up(), ->bail(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ::is_special(), ->walk_up(), ->pop(), ->remove_node() |
$subject === false && ->contains_node() && $budget && $formatting_element === null && ->has_element_in_scope() && $furthest_block === null && !->walk_up() | 84–93 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->bail(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ->walk_up(), ->pop(), ->remove_node() |
$subject === false && ->contains_node() && $budget && $formatting_element !== null && ->has_element_in_scope() && !->walk_down() && ::is_special() && $furthest_block === null && !->walk_up() | 88–101 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ::is_special(), ->walk_up(), ->pop(), ->remove_node() |
$subject === false && ->contains_node() && $budget && $formatting_element === null && ->has_element_in_scope() && !->walk_down() && ::is_special() && $furthest_block === null && !->walk_up() | 91–104 | ->get_tag(), ->current_node(), ->contains_node(), ->walk_up(), ->bail(), ->contains_node(), ->has_element_in_scope(), ->walk_down(), ::is_special(), ->walk_up(), ->pop(), ->remove_node() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 127 instructions, 19–104 executed per call, 22 branches. The work does not change between versions.
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 · 3
- WP_HTML_Processor::get_tag()Returns the uppercase name of the matched tag.
- WP_HTML_Processor::bail()Stops the parser and terminates its execution when encountering unsupported markup.
- WP_HTML_Processor::is_special()Returns whether an element of a given name is in the HTML special category.
Used by · 1
- WP_HTML_Processor::step_in_body()Parses next element in the 'in body' insertion mode.
Source code
private function run_adoption_agency_algorithm(): void { $budget = 1000; $subject = $this->get_tag(); $current_node = $this->state->stack_of_open_elements->current_node(); if ( // > If the current node is an HTML element whose tag name is subject $current_node && $subject === $current_node->node_name && // > the current node is not in the list of active formatting elements ! $this->state->active_formatting_elements->contains_node( $current_node ) ) { $this->state->stack_of_open_elements->pop(); return; } $outer_loop_counter = 0; while ( $budget-- > 0 ) { if ( $outer_loop_counter++ >= 8 ) { return; } /* * > Let formatting element be the last element in the list of active formatting elements that: * > - is between the end of the list and the last marker in the list, * > if any, or the start of the list otherwise, * > - and has the tag name subject. */ $formatting_element = null; foreach ( $this->state->active_formatting_elements->walk_up() as $item ) { if ( 'marker' === $item->node_name ) { break; } if ( $subject === $item->node_name ) { $formatting_element = $item; break; } } // > If there is no such element, then return and instead act as described in the "any other end tag" entry above. if ( null === $formatting_element ) { $this->bail( 'Cannot run adoption agency when "any other end tag" is required.' ); } // > If formatting element is not in the stack of open elements, then this is a parse error; remove the element from the list, and return. if ( ! $this->state->stack_of_open_elements->contains_node( $formatting_element ) ) { $this->state->active_formatting_elements->remove_node( $formatting_element ); return; } // > If formatting element is in the stack of open elements, but the element is not in scope, then this is a parse error; return. if ( ! $this->state->stack_of_open_elements->has_element_in_scope( $formatting_element->node_name ) ) { return; } /* * > Let furthest block be the topmost node in the stack of open elements that is lower in the stack * > than formatting element, and is an element in the special category. There might not be one. */ $is_above_formatting_element = true; $furthest_block = null; foreach ( $this->state->stack_of_open_elements->walk_down() as $item ) { if ( $is_above_formatting_element && $formatting_element->bookmark_name !== $item->bookmark_name ) { continue; } if ( $is_above_formatting_element ) { $is_above_formatting_element = false; continue; } if ( self::is_special( $item ) ) { $furthest_block = $item; break; } } /* * > If there is no furthest block, then the UA must first pop all the nodes from the bottom of the * > stack of open elements, from the current node up to and including formatting element, thenChangelog
Introduced in 6.4.0. Unchanged from 6.7.7 through 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.