WP_Style_Engine_Processor::combine_rules_selectors()
- Since
- 6.1.0
- Source
wp-includes/style-engine/class-wp-style-engine-processor.php:150
Compatibility
- WordPress
- since 6.1.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_Style_Engine_Processor::combine_rules_selectors() 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
- 7–9
- 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 79.
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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Style_Engine_Processor::combine_rules_selectors() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7–9 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 79 | 7–9 | 10 | |
| 8.5 | 79 | 7–9 | 10 | |
| 8.4 | 79 | 7–9 | 10 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 82 | 7–9 | 10 | |
| 8.2 | 82 | 7–9 | 10 | |
| 8.1 | 82 | 7–9 | 10 | |
| 7.4 | 82 | 7–9 | 10 |
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 · 2
- wp_json_encode()Encodes a variable into JSON, with some confidence checks.
- WP_Style_Engine_CSS_Rule::__construct()Constructor.
Used by · 1
- WP_Style_Engine_Processor::get_css()Gets the CSS rules as a string.
Source code
private function combine_rules_selectors() { // Build an array of selectors along with the JSON-ified styles to make comparisons easier. $selectors_json = array(); foreach ( $this->css_rules as $rule ) { $declarations = $rule->get_declarations()->get_declarations(); $declaration_options = $rule->get_declarations()->get_declaration_options(); ksort( $declarations ); // Declaration options are keyed by property and are part of the rule identity. ksort( $declaration_options ); foreach ( $declaration_options as $property => $options ) { if ( is_array( $options ) ) { ksort( $options ); $declaration_options[ $property ] = $options; } } $selectors_json[ $rule->get_selector() ] = wp_json_encode( array( 'declarations' => $declarations, 'declaration_options' => $declaration_options, ) ); } // Combine selectors that have the same styles. foreach ( $selectors_json as $selector => $json ) { // Get selectors that use the same styles. $duplicates = array_keys( $selectors_json, $json, true ); // Skip if there are no duplicates. if ( 1 >= count( $duplicates ) ) { continue; } $declarations = $this->css_rules[ $selector ]->get_declarations(); foreach ( $duplicates as $key ) { // Unset the duplicates from the $selectors_json array to avoid looping through them as well. unset( $selectors_json[ $key ] ); // Remove the rules from the rules collection. unset( $this->css_rules[ $key ] ); } // Create a new rule with the combined selectors. $duplicate_selectors = implode( ',', $duplicates ); $this->css_rules[ $duplicate_selectors ] = new WP_Style_Engine_CSS_Rule( $duplicate_selectors, $declarations ); } }Changelog
Introduced in 6.1.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/style-engine/class-wp-style-engine-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.