Don't use `array_merge()` when building comment children arrays.

`array_merge()` is much slower than building the combined array using a
`foreach` loop. The performance difference was causing a speed regression with
the `get_children()` functionality introduced in 4.4.

Merges [35931] to the 4.4 branch.

Props rogerhub.
Fixes #35025.

Built from https://develop.svn.wordpress.org/branches/4.4@35932


git-svn-id: http://core.svn.wordpress.org/branches/4.4@35896 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-12-14 19:40:45 +00:00
parent 57d0720db7
commit 6130060b53
2 changed files with 8 additions and 3 deletions

View File

@ -1330,11 +1330,16 @@ function comments_template( $file = '/comments.php', $separate_comments = false
// Trees must be flattened before they're passed to the walker. // Trees must be flattened before they're passed to the walker.
$comments_flat = array(); $comments_flat = array();
foreach ( $_comments as $_comment ) { foreach ( $_comments as $_comment ) {
$comments_flat = array_merge( $comments_flat, array( $_comment ), $_comment->get_children( array( $comments_flat[] = $_comment;
$comment_children = $_comment->get_children( array(
'format' => 'flat', 'format' => 'flat',
'status' => $comment_args['status'], 'status' => $comment_args['status'],
'orderby' => $comment_args['orderby'] 'orderby' => $comment_args['orderby']
) ) ); ) );
foreach ( $comment_children as $comment_child ) {
$comments_flat[] = $comment_child;
}
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4.1-alpha-35921'; $wp_version = '4.4.1-alpha-35932';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.