Remove redundant function calls in for loops

This commit is contained in:
Alessandro Lai 2017-12-22 10:02:44 +01:00 committed by Adrien Crivelli
parent d383bc356c
commit f246ad731d
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
11 changed files with 30 additions and 15 deletions

View File

@ -1602,7 +1602,8 @@ class Financial
// Calculate
$rate = array_shift($aArgs);
for ($i = 1; $i <= count($aArgs); ++$i) {
$countArgs = count($aArgs);
for ($i = 1; $i <= $countArgs; ++$i) {
// Is it a numeric value?
if (is_numeric($aArgs[$i - 1])) {
$returnValue += $aArgs[$i - 1] / pow(1 + $rate, $i);

View File

@ -2700,7 +2700,8 @@ class Statistical
if ((is_numeric($cumulative)) || (is_bool($cumulative))) {
if ($cumulative) {
$summer = 0;
for ($i = 0; $i <= floor($value); ++$i) {
$floor = floor($value);
for ($i = 0; $i <= $floor; ++$i) {
$summer += pow($mean, $i) / MathTrig::FACT($i);
}

View File

@ -540,7 +540,8 @@ class JpGraph implements IRenderer
$dataValuesPlot = [];
// Flatten the plot arrays to a single dimensional array to work with jpgraph
for ($j = 0; $j < count($dataValues[0]); ++$j) {
$jMax = count($dataValues[0]);
for ($j = 0; $j < $jMax; ++$j) {
for ($i = 0; $i < $seriesCount; ++$i) {
$dataValuesPlot[] = $dataValues[$i][$j];
}

View File

@ -250,7 +250,8 @@ class Slk extends BaseReader
break;
case 'S':
$styleSettings = substr($rowDatum, 1);
for ($i = 0; $i < strlen($styleSettings); ++$i) {
$iMax = strlen($styleSettings);
for ($i = 0; $i < $iMax; ++$i) {
switch ($styleSettings[$i]) {
case 'I':
$formatArray['font']['italic'] = true;
@ -386,7 +387,8 @@ class Slk extends BaseReader
break;
case 'S':
$styleSettings = substr($rowDatum, 1);
for ($i = 0; $i < strlen($styleSettings); ++$i) {
$iMax = strlen($styleSettings);
for ($i = 0; $i < $iMax; ++$i) {
switch ($styleSettings[$i]) {
case 'I':
$styleData['font']['italic'] = true;

View File

@ -1889,7 +1889,8 @@ class Xls extends BaseReader
{
$pwarray = str_repeat("\0", 64);
for ($i = 0; $i < strlen($password); ++$i) {
$iMax = strlen($password);
for ($i = 0; $i < $iMax; ++$i) {
$o = ord(substr($password, $i, 1));
$pwarray[2 * $i] = chr($o & 0xff);
$pwarray[2 * $i + 1] = chr(($o >> 8) & 0xff);
@ -3087,7 +3088,8 @@ class Xls extends BaseReader
// 1st fragment compressed
// this fragment uncompressed
$newstr = '';
for ($j = 0; $j < strlen($retstr); ++$j) {
$jMax = strlen($retstr);
for ($j = 0; $j < $jMax; ++$j) {
$newstr .= $retstr[$j] . chr(0);
}
$retstr = $newstr;

View File

@ -88,7 +88,8 @@ class File
if ($returnValue == '' || ($returnValue === null)) {
$pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
$iMax = count($pathArray);
for ($i = 0; $i < $iMax; ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i], $pathArray[$i - 1]);

View File

@ -607,7 +607,8 @@ class EigenvalueDecomposition
$this->H[$k + 1][$j] = $this->H[$k + 1][$j] - $p * $y;
}
// Column modification
for ($i = 0; $i <= min($n, $k + 3); ++$i) {
$iMax = min($n, $k + 3);
for ($i = 0; $i <= $iMax; ++$i) {
$p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k + 1];
if ($notlast) {
$p = $p + $z * $this->H[$i][$k + 2];
@ -762,7 +763,8 @@ class EigenvalueDecomposition
for ($j = $nn - 1; $j >= $low; --$j) {
for ($i = $low; $i <= $high; ++$i) {
$z = 0.0;
for ($k = $low; $k <= min($j, $high); ++$k) {
$kMax = min($j, $high);
for ($k = $low; $k <= $kMax; ++$k) {
$z = $z + $this->V[$i][$k] * $this->H[$k][$j];
}
$this->V[$i][$j] = $z;

View File

@ -81,7 +81,8 @@ class SingularValueDecomposition
// Reduce A to bidiagonal form, storing the diagonal elements
// in s and the super-diagonal elements in e.
for ($k = 0; $k < max($nct, $nrt); ++$k) {
$kMax = max($nct, $nrt);
for ($k = 0; $k < $kMax; ++$k) {
if ($k < $nct) {
// Compute the transformation for the k-th column and
// place the k-th diagonal in s[$k].
@ -518,7 +519,8 @@ class SingularValueDecomposition
$eps = pow(2.0, -52.0);
$tol = max($this->m, $this->n) * $this->s[0] * $eps;
$r = 0;
for ($i = 0; $i < count($this->s); ++$i) {
$iMax = count($this->s);
for ($i = 0; $i < $iMax; ++$i) {
if ($this->s[$i] > $tol) {
++$r;
}

View File

@ -479,7 +479,8 @@ class OLE
public static function ascToUcs($ascii)
{
$rawname = '';
for ($i = 0; $i < strlen($ascii); ++$i) {
$iMax = strlen($ascii);
for ($i = 0; $i < $iMax; ++$i) {
$rawname .= $ascii[$i]
. "\x00";
}

View File

@ -543,7 +543,8 @@ class Workbook extends BIFFwriter
foreach ($namedRanges as $namedRange) {
// Create absolute coordinate
$range = Coordinate::splitRange($namedRange->getRange());
for ($i = 0; $i < count($range); ++$i) {
$iMax = count($range);
for ($i = 0; $i < $iMax; ++$i) {
$range[$i][0] = '\'' . str_replace("'", "''", $namedRange->getWorksheet()->getTitle()) . '\'!' . Coordinate::absoluteCoordinate($range[$i][0]);
if (isset($range[$i][1])) {
$range[$i][1] = Coordinate::absoluteCoordinate($range[$i][1]);

View File

@ -315,7 +315,8 @@ class Workbook extends WriterPart
// Create absolute coordinate and write as raw text
$range = Coordinate::splitRange($pNamedRange->getRange());
for ($i = 0; $i < count($range); ++$i) {
$iMax = count($range);
for ($i = 0; $i < $iMax; ++$i) {
$range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . Coordinate::absoluteReference($range[$i][0]);
if (isset($range[$i][1])) {
$range[$i][1] = Coordinate::absoluteReference($range[$i][1]);