From: Derick Alangi Date: Sat, 12 Jan 2019 19:39:51 +0000 (+0100) Subject: Setup: Avoid using count() function in any kind of loop(s) X-Git-Tag: 1.34.0-rc.0~3075^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/File:File:Foobar.jpg?a=commitdiff_plain;h=cb2dc22b5ea2f918d579bb3d39ffa03cb3bf34e2;p=lhc%2Fweb%2Fwiklou.git Setup: Avoid using count() function in any kind of loop(s) Using count() function in loops makes things very slow because of function overheads and this function gets called everytime the loop runs meaning the bigger the value of the variable in count(), the slower the loop as its value always gets computed as the loop runs. In this case, the use of foreach(...){} is possible in order to perform the computation making it pretty fast hence improving the performance. Change-Id: Ie21fbf8f6acf72373d1da75023725b4592c80386 --- diff --git a/includes/Setup.php b/includes/Setup.php index aba050d6e3..61fad2db59 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -367,10 +367,9 @@ if ( $wgRCFilterByAge ) { // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link. sort( $wgRCLinkDays ); - // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall - for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) { - if ( $wgRCLinkDays[$i] >= $rcMaxAgeDays ) { - $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false ); + foreach ( $wgRCLinkDays as $i => $days ) { + if ( $days >= $rcMaxAgeDays ) { + array_splice( $wgRCLinkDays, $i + 1 ); break; } }