Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling function repetitively in loop conditionals #16027

Conversation

lfluvisotto
Copy link
Contributor

Avoid calling function repetitively in loop conditionals.

Description

Avoid calling function repetitively in loop conditionals for better performance.

Fixed Issues

N/A

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Jun 11, 2018

CLA assistant check
All committers have signed the CLA.

@@ -200,7 +200,7 @@ public function testTierPrices($priceScope, $expectedWebsiteId)
$this->assertTrue(is_array($tpArray));
$this->assertEquals(sizeof($tps), sizeof($tpArray));

for ($i = 0; $i < sizeof($tps); $i++) {
for ($i = 0, $iMax = sizeof($tps); $i < $iMax; $i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also replace sizeof with count?
It's alias http://php.net/manual/en/function.sizeof.php

@@ -231,7 +231,7 @@ public function testTierPrices($priceScope, $expectedWebsiteId)
$this->assertEquals(50, $tpRest->getExtensionAttributes()->getPercentageValue());
}

for ($i = 0; $i < sizeof($tps); $i++) {
for ($i = 0, $iMax = sizeof($tps); $i < $iMax; $i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also replace sizeof with count?
It's alias http://php.net/manual/en/function.sizeof.php

@@ -344,7 +344,7 @@ public function getChartUrl($directUrl = true)
}
} else {
// EXTENDED ENCODING
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
for ($j = 0, $jMax = sizeof($thisdataarray); $j < $jMax; $j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also replace sizeof with count?
It's alias http://php.net/manual/en/function.sizeof.php

@@ -331,7 +331,7 @@ public function getChartUrl($directUrl = true)
$thisdataarray = $serie;
if ($this->_encoding == "s") {
// SIMPLE ENCODING
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
for ($j = 0, $jMax = sizeof($thisdataarray); $j < $jMax; $j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also replace sizeof with count?
It's alias http://php.net/manual/en/function.sizeof.php

@orlangur orlangur self-assigned this Jun 12, 2018
@orlangur
Copy link
Contributor

@lfluvisotto sizeof and strlen are O(1) in fact while function call by itself is negligible compared to loop body thus there is no need in such changes. Also, please always target 2.2-develop branch first (you already know this from another PR, adding just for the sake of complete review).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment