Make WordPress Core

Changeset 54290


Ignore:
Timestamp:
09/23/2022 01:24:24 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r54276 r54290  
    224224
    225225    $style_handle   = generate_block_asset_handle( $metadata['name'], $field_name, $index );
    226     $block_dir      = dirname( $metadata['file'] );
    227     $style_file     = wp_normalize_path( realpath( "$block_dir/$style_path" ) );
    228     $has_style_file = false !== $style_file;
     226    $has_style_file = false !== $style_path_norm;
    229227    $version        = ! $is_core_block && isset( $metadata['version'] ) ? $metadata['version'] : false;
    230228    $style_uri      = $has_style_file ? $style_uri : false;
     
    235233        $version
    236234    );
    237     if ( file_exists( str_replace( '.css', '-rtl.css', $style_file ) ) ) {
     235    if ( file_exists( str_replace( '.css', '-rtl.css', $style_path_norm ) ) ) {
    238236        wp_style_add_data( $style_handle, 'rtl', 'replace' );
    239237    }
    240238    if ( $has_style_file ) {
    241         wp_style_add_data( $style_handle, 'path', $style_file );
    242     }
    243 
    244     $rtl_file = str_replace( "$suffix.css", "-rtl$suffix.css", $style_file );
     239        wp_style_add_data( $style_handle, 'path', $style_path_norm );
     240    }
     241
     242    $rtl_file = str_replace( "$suffix.css", "-rtl$suffix.css", $style_path_norm );
    245243    if ( is_rtl() && file_exists( $rtl_file ) ) {
    246244        wp_style_add_data( $style_handle, 'path', $rtl_file );
Note: See TracChangeset for help on using the changeset viewer.