r82100 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82099‎ | r82100 | r82101 >
Date:01:36, 14 February 2011
Author:demon
Status:ok
Tags:
Comment:
count() in for() is slow, just use a temporary variable
Modified paths:
  • /trunk/extensions/DoubleWiki/DoubleWiki_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DoubleWiki/DoubleWiki_body.php
@@ -124,7 +124,8 @@
125125 $left_chunk = '';
126126 $right_chunk = '';
127127
128 - for ( $i=0 ; $i < count( $left_slices ); $i++ ) {
 128+ $leftSliceCount = count( $left_slices );
 129+ for ( $i=0 ; $i < $leftSliceCount; $i++ ) {
129130
130131 // some slices might be empty
131132 if( $left_slices[$i] == '' ) {
@@ -171,7 +172,8 @@
172173
173174 $left_chunk = '';
174175 $right_chunk = '';
175 - for($l=0; $l < count( $left_bits ) ; $l++ ) {
 176+ $leftBitCount = count( $left_bits );
 177+ for($l=0; $l < $leftBitCount ; $l++ ) {
176178 $body .=
177179 "<tr><td valign=\"top\" style=\"vertical-align:100%;padding-right: 0.5em\" lang=\"{$left_lang}\">"
178180 ."<div style=\"width:35em; margin:0px auto\">\n".$left_bits[$l]."</div>"
@@ -206,7 +208,8 @@
207209 preg_match_all( $this->tags, $text, $m, PREG_SET_ORDER);
208210 $counter = 0;
209211 $out = '';
210 - for( $i = 0; $i < count( $m ); $i++ ){
 212+ $matchCount = count( $m );
 213+ for( $i = 0; $i < $matchCount; $i++ ){
211214 $t = $m[$i][0];
212215 if( substr( $t, 0, 2) != "</" ) {
213216 $counter++;
@@ -261,7 +264,8 @@
262265 $m = array();
263266 preg_match_all( $this->tags, $left_slices[$i], $m, PREG_SET_ORDER);
264267 $counter = 0;
265 - for($k=0 ; $k < count($m) ; $k++) {
 268+ $matchCount = count( $m );
 269+ for($k=0 ; $k < $matchCount ; $k++) {
266270 $t = $m[$k];
267271 if( substr( $t[0], 0, 2) != "</" ) {
268272 $counter++;

Follow-up revisions

RevisionCommit summaryAuthorDate
r821511.17wmf1: MFT r78964, r79086, r79087, r79091, r82004, r82025, r82048, r82070,...catrope22:55, 14 February 2011
r85027MFT various extension fixes: r81713, r81742, r81743, r81908, r81966, r81969, ...demon18:23, 30 March 2011

Status & tagging log