WordPress.org

Make WordPress Core

Changeset 5169


Ignore:
Timestamp:
04/02/07 07:03:38 (7 years ago)
Author:
matt
Message:

Fixes bottlenecks found in filter system using xdebug + kcachegrind. merge_filters was being called 1000+ times.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/plugin.php

    r5142 r5169  
    1717 */ 
    1818function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) { 
    19     global $wp_filter; 
     19    global $wp_filter, $merged_filters; 
    2020 
    2121    // So the format is wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]'] 
    2222    $wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 
     23    unset( $merged_filters[ $tag ] ); 
    2324    return true; 
    2425} 
     
    3839 */ 
    3940function apply_filters($tag, $string) { 
    40     global $wp_filter; 
    41  
    42     merge_filters($tag); 
     41    global $wp_filter, $merged_filters; 
     42 
     43    if ( !isset( $merged_filters[ $tag ] ) ) 
     44        merge_filters($tag); 
    4345 
    4446    if ( !isset($wp_filter[$tag]) ) 
     
    6971 */ 
    7072function merge_filters($tag) { 
    71     global $wp_filter; 
    72  
    73     if ( isset($wp_filter['all']) ) 
     73    global $wp_filter, $merged_filters; 
     74 
     75    if ( is_array($wp_filter['all']) ) 
    7476        $wp_filter[$tag] = array_merge($wp_filter['all'], (array) $wp_filter[$tag]); 
    7577 
     
    7880        uksort($wp_filter[$tag], "strnatcasecmp"); 
    7981    } 
     82    $merged_filters[ $tag ] = true; 
    8083} 
    8184 
     
    9396 */ 
    9497function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 
    95     global $wp_filter; 
     98    global $wp_filter, $merged_filters; 
    9699 
    97100    unset($GLOBALS['wp_filter'][$tag][$priority][serialize($function_to_remove)]); 
     101    unset( $merged_filters[ $tag ] ); 
    98102 
    99103    return true; 
Note: See TracChangeset for help on using the changeset viewer.