Skip to content

Commit

Permalink
Editor: Optimize is_callable() checks in `traverse_and_serialize_bl…
Browse files Browse the repository at this point in the history
…ocks()`.

This aims to improve performance by reducing the number of function calls.

Follow-up to [56644].

Props welcher, Cybr, mukesh27, aristath.
Fixes #62063.

git-svn-id: https://develop.svn.wordpress.org/trunk@59077 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 21, 2024
1 parent 03b12dc commit f49909e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand All @@ -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 ];
Expand Down

0 comments on commit f49909e

Please sign in to comment.