WordPress.org

Make WordPress Core

Changeset 31365


Ignore:
Timestamp:
02/07/2015 07:44:13 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Remove unnecessary array_shift() usage in get_terms() for better performance.

props bswatson, VolodymyrC.
fixes #31182.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r31346 r31365  
    20142014        }
    20152015    }
    2016     reset( $terms );
    20172016
    20182017    $_terms = array();
    20192018    if ( 'id=>parent' == $_fields ) {
    2020         while ( $term = array_shift( $terms ) ) {
    2021             $_terms[$term->term_id] = $term->parent;
     2019        foreach ( $terms as $term ) {
     2020            $_terms[ $term->term_id ] = $term->parent;
    20222021        }
    20232022    } elseif ( 'ids' == $_fields ) {
    2024         while ( $term = array_shift( $terms ) ) {
     2023        foreach ( $terms as $term ) {
    20252024            $_terms[] = $term->term_id;
    20262025        }
    20272026    } elseif ( 'names' == $_fields ) {
    2028         while ( $term = array_shift( $terms ) ) {
     2027        foreach ( $terms as $term ) {
    20292028            $_terms[] = $term->name;
    20302029        }
    20312030    } elseif ( 'id=>name' == $_fields ) {
    2032         while ( $term = array_shift( $terms ) ) {
    2033             $_terms[$term->term_id] = $term->name;
     2031        foreach ( $terms as $term ) {
     2032            $_terms[ $term->term_id ] = $term->name;
    20342033        }
    20352034    } elseif ( 'id=>slug' == $_fields ) {
    2036         while ( $term = array_shift( $terms ) ) {
    2037             $_terms[$term->term_id] = $term->slug;
     2035        foreach ( $terms as $term ) {
     2036            $_terms[ $term->term_id ] = $term->slug;
    20382037        }
    20392038    }
Note: See TracChangeset for help on using the changeset viewer.