mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@54290 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user