Ticket #8767: filters-speedup.patch

File filters-speedup.patch, 2.4 KB (added by sambauers, 3 years ago)
  • wp-includes/formatting.php

     
    207207                return ''; 
    208208        } 
    209209 
     210        // Don't bother if there are no specialchars - saves some processing 
     211        if ( !preg_match( '/[&<>"\']/', $string ) ) { 
     212                return $string; 
     213        } 
     214 
     215        // Store the site charset as a static to avoid multiple calls to wp_load_alloptions() 
    210216        if ( !$charset ) { 
    211                 $alloptions = wp_load_alloptions(); 
    212                 $charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : ''; 
     217                static $_charset; 
     218                if ( !isset( $_charset ) ) { 
     219                        $alloptions = wp_load_alloptions(); 
     220                        $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : ''; 
     221                } 
     222                $charset = $_charset; 
    213223        } 
    214224        if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) { 
    215225                $charset = 'UTF-8'; 
     
    283293                return ''; 
    284294        } 
    285295 
     296        // Don't bother if there are no entities - saves a lot of processing 
     297        if ( strpos( $string, '&' ) === false ) { 
     298                return $string; 
     299        } 
     300 
    286301        // More complete than get_html_translation_table( HTML_SPECIALCHARS ) 
    287302        $single = array( '&#039;'  => '\'', '&#x27;' => '\'' ); 
    288303        $single_preg = array( '/&#0*39;/'  => '&#039;', '/&#x0*27;/i' => '&#x27;' ); 
     
    340355                return ''; 
    341356        } 
    342357 
    343         if ( !in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) { 
     358        // Store the site charset as a static to avoid multiple calls to get_option() 
     359        static $is_utf8; 
     360        if ( !isset( $is_utf8 ) ) { 
     361                $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ); 
     362        } 
     363        if ( !$is_utf8 ) { 
    344364                return $string; 
    345365        } 
    346366 
     367        // Check for support for utf8 in the installed PCRE library once and store the result in a static 
     368        static $utf8_pcre; 
     369        if ( !isset( $utf8_pcre ) ) { 
     370                $utf8_pcre = @preg_match( '/^./u', 'a' ); 
     371        } 
     372        // We can't demand utf8 in the PCRE installation, so just return the string in those cases 
     373        if ( !$utf8_pcre ) { 
     374                return $string; 
     375        } 
     376 
    347377        // preg_match fails when it encounters invalid UTF8 in $string 
    348         if ( 1 === @preg_match( '@^.@us', $string ) ) { 
     378        if ( 1 === @preg_match( '/^./us', $string ) ) { 
    349379                return $string; 
    350380        } 
    351381 
     382        // Attempt to strip the bad chars if requested (not recommended) 
    352383        if ( $strip && function_exists( 'iconv' ) ) { 
    353384                return iconv( 'utf-8', 'utf-8', $string ); 
    354         } else { 
    355                 return ''; 
    356385        } 
     386 
     387        return ''; 
    357388} 
    358389 
    359390/**