r76461 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76460‎ | r76461 | r76462 >
Date:19:19, 10 November 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
foreach loop is pointless if you're then just going to keep a counter manually

Hence switch foreach to for loop
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -1260,10 +1260,9 @@
12611261 # First, do some preliminary work. This may shift some apostrophes from
12621262 # being mark-up to being text. It also counts the number of occurrences
12631263 # of bold and italics mark-ups.
1264 - $i = 0;
12651264 $numbold = 0;
12661265 $numitalics = 0;
1267 - foreach ( $arr as $r ) {
 1266+ for ( $i = 0; $i < count( $arr ); $i++ ) {
12681267 if ( ( $i % 2 ) == 1 ) {
12691268 # If there are ever four apostrophes, assume the first is supposed to
12701269 # be text, and the remaining three constitute mark-up for bold text.
@@ -1287,7 +1286,6 @@
12881287 $numbold++;
12891288 }
12901289 }
1291 - $i++;
12921290 }
12931291
12941292 # If there is an odd number of both bold and italics, it is likely

Comments

#Comment by Nikerabbit (talk | contribs)   13:03, 11 November 2010

Or foreach( $arr as $i => $r );, throw in array_values() if needed.

#Comment by Reedy (talk | contribs)   14:07, 11 November 2010

It wasn't using the $r, so it seemed more sensible just to use a for loop

Status & tagging log