[wp-trac] [WordPress Trac] #18230: Optimize wp_list_pluck

WordPress Trac wp-trac at lists.automattic.com
Tue Aug 2 21:16:58 UTC 2011


#18230: Optimize wp_list_pluck
-------------------------+------------------
 Reporter:  Otto42       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.3
Component:  Performance  |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------

Comment (by Otto42):

 If you make that assumption that the $list array is full of similar
 objects or arrays, you do get a big speedup.

 {{{
 function new2_wp_list_pluck( $list, $field ) {
         if ( is_object( $list[0] ) ) {
                 foreach ( $list as $key => $value )
                         $list[ $key ] = $value->$field;
         } else {
                 foreach ( $list as $key => $value )
                         $list[ $key ] = $value[ $field ];
         }

         return $list;
 }

 float(1.2270720005035) : OLD
 float(0.61718487739563) : NEW
 float(0.35837507247925) : NEW2

 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18230#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list