Don't call the size function count() as part of a test condition in loops. Compute the size beforehand, and not on each iteration.

Scrutinizer added a Performance label: these are the only violations.

See #30799.

Built from https://develop.svn.wordpress.org/trunk@31554


git-svn-id: http://core.svn.wordpress.org/trunk@31535 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-02-26 05:48:24 +00:00
parent 94bd0f93b8
commit 7cb45f2402
6 changed files with 10 additions and 8 deletions

View File

@ -371,9 +371,11 @@ class WP_Filesystem_Base {
$legal = array('', 'w', 'r', 'x', '-'); $legal = array('', 'w', 'r', 'x', '-');
$attarray = preg_split('//', $mode); $attarray = preg_split('//', $mode);
for ($i=0; $i < count($attarray); $i++) for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
if ($key = array_search($attarray[$i], $legal)) if ($key = array_search($attarray[$i], $legal)) {
$realmode .= $legal[$key]; $realmode .= $legal[$key];
}
}
$mode = str_pad($realmode, 10, '-', STR_PAD_LEFT); $mode = str_pad($realmode, 10, '-', STR_PAD_LEFT);
$trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1'); $trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1');

View File

@ -461,7 +461,7 @@ function image_edit_apply_changes( $image, $changes ) {
// Combine operations. // Combine operations.
if ( count($changes) > 1 ) { if ( count($changes) > 1 ) {
$filtered = array($changes[0]); $filtered = array($changes[0]);
for ( $i = 0, $j = 1; $j < count($changes); $j++ ) { for ( $i = 0, $j = 1, $c = count( $changes ); $j < $c; $j++ ) {
$combined = false; $combined = false;
if ( $filtered[$i]->type == $changes[$j]->type ) { if ( $filtered[$i]->type == $changes[$j]->type ) {
switch ( $filtered[$i]->type ) { switch ( $filtered[$i]->type ) {

View File

@ -1756,7 +1756,7 @@ function make_url_footnote( $content ) {
_deprecated_function( __FUNCTION__, '2.9', '' ); _deprecated_function( __FUNCTION__, '2.9', '' );
preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches ); preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
$links_summary = "\n"; $links_summary = "\n";
for ( $i=0; $i<count($matches[0]); $i++ ) { for ( $i = 0, $c = count( $matches[0] ); $i < $c; $i++ ) {
$link_match = $matches[0][$i]; $link_match = $matches[0][$i];
$link_number = '['.($i+1).']'; $link_number = '['.($i+1).']';
$link_url = $matches[2][$i]; $link_url = $matches[2][$i];

View File

@ -633,9 +633,9 @@ function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = fals
// Now re-encode everything except &entity; // Now re-encode everything except &entity;
$string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
for ( $i = 0; $i < count( $string ); $i += 2 ) for ( $i = 0, $c = count( $string ); $i < $c; $i += 2 ) {
$string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
}
$string = implode( '', $string ); $string = implode( '', $string );
} }

View File

@ -1516,7 +1516,7 @@ function wp_mkdir_p( $target ) {
*/ */
if ( $dir_perms != ( $dir_perms & ~umask() ) ) { if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) ); $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
for ( $i = 1; $i <= count( $folder_parts ); $i++ ) { for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
@chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms ); @chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
} }
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-alpha-31553'; $wp_version = '4.2-alpha-31554';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.