Make WordPress Core

Changeset 31829


Ignore:
Timestamp:
03/19/2015 03:55:39 AM (10 years ago)
Author:
wonderboymusic
Message:

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

Props SergeyBiryukov.
Fixes #31259.

Location:
trunk/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r31811 r31829  
    10921092
    10931093            $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
    1094             $_menu_item = array_shift( $_menu_items );
     1094            $_menu_item = reset( $_menu_items );
    10951095
    10961096            // Restore the missing menu item properties
     
    17941794            wp_die( $error );
    17951795
    1796         $_POST['widget-' . $id_base] = array( $multi_number => array_shift($settings) );
     1796        $_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) );
    17971797        $widget_id = $id_base . '-' . $multi_number;
    17981798        $sidebar[] = $widget_id;
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r31441 r31829  
    19051905            case 'plugin':
    19061906                $plugin_data = get_plugins( '/' . $update->slug );
    1907                 $plugin_data = array_shift( $plugin_data );
     1907                $plugin_data = reset( $plugin_data );
    19081908                if ( $plugin_data )
    19091909                    return $plugin_data['Name'];
  • trunk/src/wp-admin/includes/media.php

    r31799 r31829  
    622622
    623623    if ( isset($_POST['send']) ) {
    624         $keys = array_keys($_POST['send']);
    625         $send_id = (int) array_shift($keys);
     624        $keys = array_keys( $_POST['send'] );
     625        $send_id = (int) reset( $keys );
    626626    }
    627627
     
    13581358    $post_mime_types = get_post_mime_types();
    13591359    $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
    1360     $type = array_shift( $keys );
     1360    $type = reset( $keys );
    13611361    $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
    13621362
  • trunk/src/wp-admin/includes/menu.php

    r31300 r31829  
    9595        continue;
    9696    $subs = $submenu[$data[2]];
    97     $first_sub = array_shift($subs);
     97    $first_sub = reset( $subs );
    9898    $old_parent = $data[2];
    9999    $new_parent = $first_sub[2];
     
    164164    if ( ! empty( $submenu[$data[2]] ) && 1 == count ( $submenu[$data[2]] ) ) {
    165165        $subs = $submenu[$data[2]];
    166         $first_sub = array_shift($subs);
     166        $first_sub = reset( $subs );
    167167        if ( $data[2] == $first_sub[2] )
    168168            unset( $submenu[$data[2]] );
  • trunk/src/wp-admin/includes/ms.php

    r31517 r31829  
    805805            <?php
    806806            if ( !$found ) {
    807                 $blog = array_shift( $all_blogs );
     807                $blog = reset( $all_blogs );
    808808                update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
    809809            }
    810810        } elseif ( count( $all_blogs ) == 1 ) {
    811             $blog = array_shift( $all_blogs );
     811            $blog = reset( $all_blogs );
    812812            echo $blog->domain;
    813813            if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
  • trunk/src/wp-admin/includes/plugin-install.php

    r31363 r31829  
    305305            } else {
    306306                $key = array_keys( $installed_plugin );
    307                 $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
     307                $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
    308308                $update_file = $api->slug . '/' . $key;
    309309                if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){
     
    392392    if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) {
    393393        $section_titles = array_keys( (array) $api->sections );
    394         $section = array_shift( $section_titles );
     394        $section = reset( $section_titles );
    395395    }
    396396
  • trunk/src/wp-admin/user-edit.php

    r31516 r31829  
    316316// Compare user role against currently editable roles
    317317$user_roles = array_intersect( array_values( $profileuser->roles ), array_keys( get_editable_roles() ) );
    318 $user_role  = array_shift( $user_roles );
     318$user_role  = reset( $user_roles );
    319319
    320320// print the full list of roles with the primary one selected.
  • trunk/src/wp-admin/widgets.php

    r31420 r31829  
    190190        // Default to the first sidebar
    191191        $keys = array_keys( $wp_registered_sidebars );
    192         $sidebar = array_shift( $keys );
     192        $sidebar = reset( $keys );
    193193
    194194        if ( isset($_GET['base']) && isset($_GET['num']) ) { // multi-widget
  • trunk/src/wp-includes/pomo/streams.php

    r30663 r31829  
    4141        $endian_letter = ('big' == $this->endian)? 'N' : 'V';
    4242        $int = unpack($endian_letter, $bytes);
    43         return array_shift($int);
     43        return reset( $int );
    4444    }
    4545
  • trunk/src/wp-includes/post-formats.php

    r31168 r31829  
    2727        return false;
    2828
    29     $format = array_shift( $_format );
     29    $format = reset( $_format );
    3030
    3131    return str_replace('post-format-', '', $format->slug );
  • trunk/src/wp-includes/post.php

    r31789 r31829  
    46004600
    46014601    if ( 1 == count( $post_status ) ) {
    4602         $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], array_shift( $post_status ) );
     4602        $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) );
    46034603    } else {
    46044604        $post_status = implode( "', '", $post_status );
  • trunk/src/wp-includes/query.php

    r31458 r31829  
    46744674            if ( count( $post_type ) > 1 )
    46754675                return;
    4676             $post_type = array_shift( $post_type );
     4676            $post_type = reset( $post_type );
    46774677        }
    46784678
Note: See TracChangeset for help on using the changeset viewer.