wppaste
WordPress

WP_Style_Engine_Processor::combine_rules_selectors()

Since
6.1.0
Source
wp-includes/style-engine/class-wp-style-engine-processor.php:150
Combines selectors from the rules store when they have the same styles.

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
7–9

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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.

WhenInstructionsCalls it makes
always7–9none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev797–910
8.5797–910
8.4797–9103 fewer instructions than PHP 8.3
8.3827–910
8.2827–910
8.1827–910
7.4827–910

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

Used by · 1

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.

  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/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.