From d2c835af27d4e4c42b97f422a0aa98b8fd3fb7cd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 21 Sep 2024 14:41:17 +0000 Subject: [PATCH] Editor: Optimize `is_callable()` checks in `traverse_and_serialize_blocks()`. This aims to improve performance by reducing the number of function calls. Follow-up to [56644]. Props welcher, Cybr, mukesh27, aristath. Fixes #62063. Built from https://develop.svn.wordpress.org/trunk@59077 git-svn-id: http://core.svn.wordpress.org/trunk@58473 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 7 +++++-- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 1a8f3459c5..9e3e470304 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -1690,8 +1690,11 @@ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_cal $result = ''; $parent_block = null; // At the top level, there is no parent block to pass to the callbacks; yet the callbacks expect a reference. + $pre_callback_is_callable = is_callable( $pre_callback ); + $post_callback_is_callable = is_callable( $post_callback ); + foreach ( $blocks as $index => $block ) { - if ( is_callable( $pre_callback ) ) { + if ( $pre_callback_is_callable ) { $prev = 0 === $index ? null : $blocks[ $index - 1 ]; @@ -1702,7 +1705,7 @@ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_cal ); } - if ( is_callable( $post_callback ) ) { + if ( $post_callback_is_callable ) { $next = count( $blocks ) - 1 === $index ? null : $blocks[ $index + 1 ]; diff --git a/wp-includes/version.php b/wp-includes/version.php index 4552bd00e6..2029a1d210 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-59076'; +$wp_version = '6.7-alpha-59077'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.