Blocks: Remove duplicate use of realpath() in register_block_style_handle().

The `register_block_style_handle()` function called `realpath()` when retrieving the normalized style path, and then a few lines below that, recalculated the exact same value, running `realpath()` again.

This commit removes duplicate calculations, reducing the number of `realpath()` calls in the function by half. In tests ran using Xdebug & Webgrind, the total `realpath()` invocation count goes down from 639 to 461, and total self cost (the time that the function is responsible for) goes down from 146 ms to 89 ms.

Follow-up to [48141], [52291], [53091], [54155].

Props aristath.
Fixes #56636.
Built from https://develop.svn.wordpress.org/trunk@54290


git-svn-id: http://core.svn.wordpress.org/trunk@53849 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-09-23 13:26:09 +00:00
parent d963f95253
commit 4d6518c2d5
2 changed files with 5 additions and 7 deletions

View File

@ -223,9 +223,7 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
}
$style_handle = generate_block_asset_handle( $metadata['name'], $field_name, $index );
$block_dir = dirname( $metadata['file'] );
$style_file = wp_normalize_path( realpath( "$block_dir/$style_path" ) );
$has_style_file = false !== $style_file;
$has_style_file = false !== $style_path_norm;
$version = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false;
$style_uri = $has_style_file ? $style_uri : false;
$result = wp_register_style(
@ -234,14 +232,14 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
array(),
$version
);
if ( file_exists( str_replace( '.css', '-rtl.css', $style_file ) ) ) {
if ( file_exists( str_replace( '.css', '-rtl.css', $style_path_norm ) ) ) {
wp_style_add_data( $style_handle, 'rtl', 'replace' );
}
if ( $has_style_file ) {
wp_style_add_data( $style_handle, 'path', $style_file );
wp_style_add_data( $style_handle, 'path', $style_path_norm );
}
$rtl_file = str_replace( "$suffix.css", "-rtl$suffix.css", $style_file );
$rtl_file = str_replace( "$suffix.css", "-rtl$suffix.css", $style_path_norm );
if ( is_rtl() && file_exists( $rtl_file ) ) {
wp_style_add_data( $style_handle, 'path', $rtl_file );
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-beta1-54289';
$wp_version = '6.1-beta1-54290';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.