Make WordPress Core

Changeset 31554


Ignore:
Timestamp:
02/26/2015 05:47:53 AM (10 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-filesystem-base.php

    r31212 r31554  
    372372        $attarray = preg_split('//', $mode);
    373373
    374         for ($i=0; $i < count($attarray); $i++)
    375            if ($key = array_search($attarray[$i], $legal))
     374        for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
     375           if ($key = array_search($attarray[$i], $legal)) {
    376376               $realmode .= $legal[$key];
     377           }
     378        }
    377379
    378380        $mode = str_pad($realmode, 10, '-', STR_PAD_LEFT);
  • trunk/src/wp-admin/includes/image-edit.php

    r31529 r31554  
    462462    if ( count($changes) > 1 ) {
    463463        $filtered = array($changes[0]);
    464         for ( $i = 0, $j = 1; $j < count($changes); $j++ ) {
     464        for ( $i = 0, $j = 1, $c = count( $changes ); $j < $c; $j++ ) {
    465465            $combined = false;
    466466            if ( $filtered[$i]->type == $changes[$j]->type ) {
  • trunk/src/wp-includes/deprecated.php

    r31212 r31554  
    17571757    preg_match_all( '/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches );
    17581758    $links_summary = "\n";
    1759     for ( $i=0; $i<count($matches[0]); $i++ ) {
     1759    for ( $i = 0, $c = count( $matches[0] ); $i < $c; $i++ ) {
    17601760        $link_match = $matches[0][$i];
    17611761        $link_number = '['.($i+1).']';
  • trunk/src/wp-includes/formatting.php

    r31249 r31554  
    634634        $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
    635635
    636         for ( $i = 0; $i < count( $string ); $i += 2 )
     636        for ( $i = 0, $c = count( $string ); $i < $c; $i += 2 ) {
    637637            $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
    638 
     638        }
    639639        $string = implode( '', $string );
    640640    }
  • trunk/src/wp-includes/functions.php

    r31451 r31554  
    15171517        if ( $dir_perms != ( $dir_perms & ~umask() ) ) {
    15181518            $folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
    1519             for ( $i = 1; $i <= count( $folder_parts ); $i++ ) {
     1519            for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
    15201520                @chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
    15211521            }
Note: See TracChangeset for help on using the changeset viewer.