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.

git-svn-id: https://develop.svn.wordpress.org/trunk@56457 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
David Baumwald
2023-08-24 19:57:15 +00:00
parent b1f5563e31
commit 095617ed94

View File

@@ -539,7 +539,7 @@ function wp_get_block_css_selector( $block_type, $target = 'root', $fallback = f
// Prefer the selectors API if available.
if ( $has_selectors ) {
// Look for selector under `feature.root`.
$path = array_merge( $target, array( 'root' ) );
$path = array( current( $target ), 'root' );
$feature_selector = _wp_array_get( $block_type->selectors, $path, null );
if ( $feature_selector ) {
@@ -553,7 +553,7 @@ function wp_get_block_css_selector( $block_type, $target = 'root', $fallback = f
}
// Try getting old experimental supports selector value.
$path = array_merge( $target, array( '__experimentalSelector' ) );
$path = array( current( $target ), '__experimentalSelector' );
$feature_selector = _wp_array_get( $block_type->supports, $path, null );
// Nothing to work with, provide fallback or null.