Blocks: Avoid extra calls to `realpath()` in block scripts and styles registration.

This affects:
* `register_block_script_handle()`
* `register_block_style_handle()`

Both functions set a variable with this code:
{{{
$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
}}}

That value never changes during page load, so we can save it to a static variable. By doing so, we can avoid ~200 calls to `realpath()` and `wp_normalize_path()`, or even more if third-party plugins register scripts or styles.

Follow-up to [52291], [52939], [54290], [54291], [54309], [54327].

Props aristath, mukesh27, SergeyBiryukov.
Fixes #56758.
Built from https://develop.svn.wordpress.org/trunk@54415


git-svn-id: http://core.svn.wordpress.org/trunk@53974 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-10-07 15:46:12 +00:00
parent 8a8bd9192b
commit 59b066ef11
2 changed files with 10 additions and 3 deletions

View File

@ -129,7 +129,11 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) {
}
// Path needs to be normalized to work in Windows env.
$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
static $wpinc_path_norm = '';
if ( ! $wpinc_path_norm ) {
$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
}
$theme_path_norm = wp_normalize_path( get_theme_file_path() );
$script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) );
@ -182,7 +186,10 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
return false;
}
$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
static $wpinc_path_norm = '';
if ( ! $wpinc_path_norm ) {
$wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) );
}
$is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm );
// Skip registering individual styles for each core block when a bundled version provided.

View File

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