Skip to content

Commit 8fb5cd2

Browse files
author
Stanislav Idolov
authored
ENGCOM-1020: [Forwardport] Performance: remove count() form the condition section of a loop #14195
2 parents 0419d09 + b7f6abd commit 8fb5cd2

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

app/code/Magento/Backend/Model/Widget/Grid/Parser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public function parseExpression($expression)
3030
$expression = trim($expression);
3131
foreach ($this->_operations as $operation) {
3232
$splittedExpr = preg_split('/\\' . $operation . '/', $expression, -1, PREG_SPLIT_DELIM_CAPTURE);
33-
if (count($splittedExpr) > 1) {
34-
for ($i = 0; $i < count($splittedExpr); $i++) {
33+
$count = count($splittedExpr);
34+
if ($count > 1) {
35+
for ($i = 0; $i < $count; $i++) {
3536
$stack = array_merge($stack, $this->parseExpression($splittedExpr[$i]));
3637
if ($i > 0) {
3738
$stack[] = $operation;

app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Price.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ public function getMaxPrice()
282282
public function getPriorFilters($filterParams)
283283
{
284284
$priorFilters = [];
285-
for ($i = 1; $i < count($filterParams); ++$i) {
285+
$count = count($filterParams);
286+
for ($i = 1; $i < $count; ++$i) {
286287
$priorFilter = $this->validateFilter($filterParams[$i]);
287288
if ($priorFilter) {
288289
$priorFilters[] = $priorFilter;

app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/Dependency/MapperTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public function testGetDependenciesWhenDependentIsInvisible($isValueSatisfy)
9898
{
9999
$expected = [];
100100
$rowData = array_values($this->_testData);
101-
for ($i = 0; $i < count($this->_testData); ++$i) {
101+
$count = count($this->_testData);
102+
for ($i = 0; $i < $count; ++$i) {
102103
$data = $rowData[$i];
103104
$dependentPath = 'some path ' . $i;
104105
$field = $this->_getField(
@@ -158,7 +159,8 @@ public function testGetDependenciesIsVisible()
158159
{
159160
$expected = [];
160161
$rowData = array_values($this->_testData);
161-
for ($i = 0; $i < count($this->_testData); ++$i) {
162+
$count = count($this->_testData);
163+
for ($i = 0; $i < $count; ++$i) {
162164
$data = $rowData[$i];
163165
$field = $this->_getField(
164166
true,

app/code/Magento/Paypal/Model/Report/Settlement.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ public function parseCsv($localCsv, $format = 'new')
369369
// Section columns.
370370
// In case ever the column order is changed, we will have the items recorded properly
371371
// anyway. We have named, not numbered columns.
372-
for ($i = 1; $i < count($line); $i++) {
372+
$count = count($line);
373+
for ($i = 1; $i < $count; $i++) {
373374
$sectionColumns[$line[$i]] = $i;
374375
}
375376
$flippedSectionColumns = array_flip($sectionColumns);

app/code/Magento/Usps/Model/Carrier.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,8 @@ protected function _parseZip($zipString, $returnFull = false)
20542054
if (preg_match('/[\\d\\w]{5}\\-[\\d\\w]{4}/', $zipString) != 0) {
20552055
$zip = explode('-', $zipString);
20562056
}
2057-
for ($i = 0; $i < count($zip); ++$i) {
2057+
$count = count($zip);
2058+
for ($i = 0; $i < $count; ++$i) {
20582059
if (strlen($zip[$i]) == 5) {
20592060
$zip5 = $zip[$i];
20602061
} elseif (strlen($zip[$i]) == 4) {

app/code/Magento/Webapi/Model/Rest/Swagger/Generator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ private function handlePrimitive($name, $prefix)
749749
private function convertPathParams($uri)
750750
{
751751
$parts = explode('/', $uri);
752-
for ($i=0; $i < count($parts); $i++) {
752+
$count = count($parts);
753+
for ($i=0; $i < $count; $i++) {
753754
if (strpos($parts[$i], ':') === 0) {
754755
$parts[$i] = '{' . substr($parts[$i], 1) . '}';
755756
}

app/code/Magento/Webapi/Model/Soap/Wsdl/ComplexTypeStrategy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ public function addAnnotation(\DOMElement $element, $documentation, $default = n
229229
$this->_processElementType($elementType, $documentation, $appInfoNode);
230230

231231
if (preg_match_all('/{([a-z]+):(.+)}/Ui', $documentation, $matches)) {
232-
for ($i = 0; $i < count($matches[0]); $i++) {
232+
$count = count($matches[0]);
233+
for ($i = 0; $i < $count; $i++) {
233234
$appinfoTag = $matches[0][$i];
234235
$tagName = $matches[1][$i];
235236
$tagValue = $matches[2][$i];

0 commit comments

Comments
 (0)