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

array_push(...) calls behaving as '$array[] = ...', $array[] = works faster than invoking functions in PHP #16144

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ protected function orderCountryOptions(array $countryOptions)
]];
foreach ($countryOptions as $countryOption) {
if (empty($countryOption['value']) || in_array($countryOption['value'], $this->topCountryCodes)) {
array_push($headOptions, $countryOption);
$headOptions[] = $countryOption;
} else {
array_push($tailOptions, $countryOption);
$tailOptions[] = $countryOption;
}
}
return array_merge($headOptions, $tailOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ private function orderCountryOptions(array $countryOptions)
]];
foreach ($countryOptions as $countryOption) {
if (empty($countryOption['value']) || in_array($countryOption['value'], $topCountryCodes)) {
array_push($headOptions, $countryOption);
$headOptions[] = $countryOption;
} else {
array_push($tailOptions, $countryOption);
$tailOptions[] = $countryOption;
}
}
return array_merge($headOptions, $tailOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private function buildMap($filePath, $packagePath, $contentType)
if (!isset($this->map[$filePath])) {
$this->map[$filePath] = [];
}
array_push($this->map[$filePath], $resolvedMapPath);
$this->map[$filePath][] = $resolvedMapPath;
$this->buildMap($resolvedMapPath, $packagePath, $contentType);
};
if ($content) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/ImportExport/Model/Report/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function createReport(
$outputCsv = $this->createOutputCsvModel($outputFileName);

$columnsName = $sourceCsv->getColNames();
array_push($columnsName, self::REPORT_ERROR_COLUMN_NAME);
$columnsName[] = self::REPORT_ERROR_COLUMN_NAME;
$outputCsv->setHeaderCols($columnsName);

foreach ($sourceCsv as $rowNum => $rowData) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Quote/Model/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ public function getErrors()
foreach ($this->getMessages() as $message) {
/* @var $error \Magento\Framework\Message\AbstractMessage */
if ($message->getType() == \Magento\Framework\Message\MessageInterface::TYPE_ERROR) {
array_push($errors, $message);
$errors[] = $message;
}
}
return $errors;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/SalesRule/Model/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public function sortItemsByPriority($items, Address $address = null)
foreach ($items as $itemKey => $itemValue) {
if ($rule->getActions()->validate($itemValue)) {
unset($items[$itemKey]);
array_push($itemsSorted, $itemValue);
$itemsSorted[] = $itemValue;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ protected function parse($filterString)
}
switch ($filterString[$position]) {
case '[':
array_push($parent, $currentElement);
$parent[] = $currentElement;
// push current field in stack and initialize current
array_push($stack, $current);
$stack[] = $current;
$current = [];
break;

Expand Down
4 changes: 2 additions & 2 deletions setup/src/Magento/Setup/Module/Dependency/Circular.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function buildCircular($modules)
return;
}
$this->circularDependencies[$path] = $modules;
array_push($modules, array_shift($modules));
$modules[] = array_shift($modules);
$this->buildCircular($modules);
}

Expand All @@ -133,7 +133,7 @@ protected function divideByModules($circularDependencies)
$dependenciesByModule = [];
foreach ($circularDependencies as $circularDependency) {
$module = $circularDependency[0];
array_push($circularDependency, $module);
$circularDependency[] = $module;
$dependenciesByModule[$module][] = $circularDependency;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ protected function _collectEntitiesFromString($content)
$attributes = $entityNode->attributes;
$type = $attributes->getNamedItem('type');
if ($type !== null) {
array_push($output, $type->nodeValue);
$output[] = $type->nodeValue;
} else {
array_push($output, $attributes->getNamedItem('name')->nodeValue);
$output[] = $attributes->getNamedItem('name')->nodeValue;
}
}
return $output;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function _filterEntities(array $output)
$this->_handleControllerClassName($entityName);
}
if (class_exists($entityName) || interface_exists($entityName)) {
array_push($filteredEntities, $entityName . '\\Interceptor');
$filteredEntities[] = $entityName . '\\Interceptor';
}
}
return $filteredEntities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function _filterEntities(array $output)
}
if (false === $isClassExists) {
if (class_exists($entityName) || interface_exists($entityName)) {
array_push($filteredEntities, $className);
$filteredEntities[] = $className;
} else {
$this->_log->add(
\Magento\Setup\Module\Di\Compiler\Log\Log::CONFIGURATION_ERROR,
Expand Down