Replace `array_shift()` with `reset()` where appropriate for performance.

Props SergeyBiryukov.
Fixes #31259.

Built from https://develop.svn.wordpress.org/trunk@31829


git-svn-id: http://core.svn.wordpress.org/trunk@31811 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-03-19 03:56:27 +00:00
parent 55ae3f9ea0
commit bce851dcf2
13 changed files with 19 additions and 19 deletions

View File

@ -1091,7 +1091,7 @@ function wp_ajax_add_menu_item() {
}
$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
$_menu_item = array_shift( $_menu_items );
$_menu_item = reset( $_menu_items );
// Restore the missing menu item properties
$menu_item_data['menu-item-description'] = $_menu_item->description;
@ -1793,7 +1793,7 @@ function wp_ajax_save_widget() {
if ( !$multi_number )
wp_die( $error );
$_POST['widget-' . $id_base] = array( $multi_number => array_shift($settings) );
$_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) );
$widget_id = $id_base . '-' . $multi_number;
$sidebar[] = $widget_id;
}

View File

@ -1904,7 +1904,7 @@ class Language_Pack_Upgrader extends WP_Upgrader {
break;
case 'plugin':
$plugin_data = get_plugins( '/' . $update->slug );
$plugin_data = array_shift( $plugin_data );
$plugin_data = reset( $plugin_data );
if ( $plugin_data )
return $plugin_data['Name'];
break;

View File

@ -621,8 +621,8 @@ function media_upload_form_handler() {
$errors = null;
if ( isset($_POST['send']) ) {
$keys = array_keys($_POST['send']);
$send_id = (int) array_shift($keys);
$keys = array_keys( $_POST['send'] );
$send_id = (int) reset( $keys );
}
if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
@ -1357,7 +1357,7 @@ function get_media_item( $attachment_id, $args = null ) {
$post_mime_types = get_post_mime_types();
$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
$type = array_shift( $keys );
$type = reset( $keys );
$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
$form_fields = get_attachment_fields_to_edit( $post, $r['errors'] );

View File

@ -94,7 +94,7 @@ foreach ( $menu as $id => $data ) {
if ( empty($submenu[$data[2]]) )
continue;
$subs = $submenu[$data[2]];
$first_sub = array_shift($subs);
$first_sub = reset( $subs );
$old_parent = $data[2];
$new_parent = $first_sub[2];
/*
@ -163,7 +163,7 @@ foreach ( $menu as $id => $data ) {
*/
if ( ! empty( $submenu[$data[2]] ) && 1 == count ( $submenu[$data[2]] ) ) {
$subs = $submenu[$data[2]];
$first_sub = array_shift($subs);
$first_sub = reset( $subs );
if ( $data[2] == $first_sub[2] )
unset( $submenu[$data[2]] );
}

View File

@ -804,11 +804,11 @@ function choose_primary_blog() {
</select>
<?php
if ( !$found ) {
$blog = array_shift( $all_blogs );
$blog = reset( $all_blogs );
update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
}
} elseif ( count( $all_blogs ) == 1 ) {
$blog = array_shift( $all_blogs );
$blog = reset( $all_blogs );
echo $blog->domain;
if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );

View File

@ -304,7 +304,7 @@ function install_plugin_install_status($api, $loop = false) {
$url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug);
} else {
$key = array_keys( $installed_plugin );
$key = array_shift( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
$key = reset( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
$update_file = $api->slug . '/' . $key;
if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){
$status = 'latest_installed';
@ -391,7 +391,7 @@ function install_plugin_information() {
$section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English.
if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
$section_titles = array_keys( (array) $api->sections );
$section = array_shift( $section_titles );
$section = reset( $section_titles );
}
iframe_header( __( 'Plugin Install' ) );

View File

@ -315,7 +315,7 @@ do_action( 'personal_options', $profileuser );
<?php
// Compare user role against currently editable roles
$user_roles = array_intersect( array_values( $profileuser->roles ), array_keys( get_editable_roles() ) );
$user_role = array_shift( $user_roles );
$user_role = reset( $user_roles );
// print the full list of roles with the primary one selected.
wp_dropdown_roles($user_role);

View File

@ -189,7 +189,7 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
if ( isset($_GET['addnew']) ) {
// Default to the first sidebar
$keys = array_keys( $wp_registered_sidebars );
$sidebar = array_shift( $keys );
$sidebar = reset( $keys );
if ( isset($_GET['base']) && isset($_GET['num']) ) { // multi-widget
// Copy minimal info from an existing instance of this widget to a new instance

View File

@ -40,7 +40,7 @@ class POMO_Reader {
return false;
$endian_letter = ('big' == $this->endian)? 'N' : 'V';
$int = unpack($endian_letter, $bytes);
return array_shift($int);
return reset( $int );
}
/**

View File

@ -26,7 +26,7 @@ function get_post_format( $post = null ) {
if ( empty( $_format ) )
return false;
$format = array_shift( $_format );
$format = reset( $_format );
return str_replace('post-format-', '', $format->slug );
}

View File

@ -4599,7 +4599,7 @@ function get_pages( $args = array() ) {
}
if ( 1 == count( $post_status ) ) {
$where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], array_shift( $post_status ) );
$where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) );
} else {
$post_status = implode( "', '", $post_status );
$where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] );

View File

@ -4673,7 +4673,7 @@ function wp_old_slug_redirect() {
if ( is_array( $post_type ) ) {
if ( count( $post_type ) > 1 )
return;
$post_type = array_shift( $post_type );
$post_type = reset( $post_type );
}
// Do not attempt redirect for hierarchical post types

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-beta1-31828';
$wp_version = '4.2-beta1-31829';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.