Editor: Improve the append_to_selector method.

Improve `append_to_selector` method in `WP_Theme_JSON` by checking to see if string contains a common before imploding / exploding string, which improves performance. 

Originally developed and tested in [WordPress/gutenberg#47833 Gutenberg PR 47833].

Props spacedmonkey, flixos90, mukesh27, joemcgill, wildworks, oandregal, mamaduka.
Fixes #58231.
Built from https://develop.svn.wordpress.org/trunk@55907


git-svn-id: http://core.svn.wordpress.org/trunk@55419 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2023-06-12 11:22:23 +00:00
parent f8cd908be2
commit a56a09c4ba
2 changed files with 4 additions and 1 deletions

View File

@ -789,6 +789,9 @@ class WP_Theme_JSON {
* @return string The new selector. * @return string The new selector.
*/ */
protected static function append_to_selector( $selector, $to_append, $position = 'right' ) { protected static function append_to_selector( $selector, $to_append, $position = 'right' ) {
if ( ! str_contains( $selector, ',' ) ) {
return 'right' === $position ? $selector . $to_append : $to_append . $selector;
}
$new_selectors = array(); $new_selectors = array();
$selectors = explode( ',', $selector ); $selectors = explode( ',', $selector );
foreach ( $selectors as $sel ) { foreach ( $selectors as $sel ) {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.3-alpha-55906'; $wp_version = '6.3-alpha-55907';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.