Make WordPress Core


Ignore:
Timestamp:
08/24/2023 07:57:15 PM (15 months ago)
Author:
davidbaumwald
Message:

Editor: Optimize wp_get_block_css_selector to remove array_merge calls for better performance.

Some block themes like TT3 use wp_get_block_css_selector to determine a CSS selector based on block type and other parameters. However, recent performance profiling indicated a bottleneck in wp_get_block_css_selector, particularly sections that utilize array_merge. By slightly refactoring these sections, array_merge calls can be avoided which increases performance.

Props mukesh27, joemcgill, daxelrod, tabrisrp.
Fixes #59178.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/global-styles-and-settings.php

    r56413 r56457  
    540540        if ( $has_selectors ) {
    541541            // Look for selector under `feature.root`.
    542             $path             = array_merge( $target, array( 'root' ) );
     542            $path             = array( current( $target ), 'root' );
    543543            $feature_selector = _wp_array_get( $block_type->selectors, $path, null );
    544544
     
    554554
    555555        // Try getting old experimental supports selector value.
    556         $path             = array_merge( $target, array( '__experimentalSelector' ) );
     556        $path             = array( current( $target ), '__experimentalSelector' );
    557557        $feature_selector = _wp_array_get( $block_type->supports, $path, null );
    558558
Note: See TracChangeset for help on using the changeset viewer.