-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from magento/pre-release
Pre 2.0.0 release improvements and fixes
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Rule: array_merge(...) is used in a loop and is a resources greedy construction | ||
|
||
## Reason | ||
Merging arrays in a loop is slow and causes high CPU usage. | ||
|
||
## How to Fix | ||
Typical example when `array_merge` is being used in the loop: | ||
``` php | ||
$options = []; | ||
foreach ($configurationSources as $source) { | ||
// code here | ||
$options = array_merge($options, $source->getOptions()); | ||
} | ||
``` | ||
|
||
In order to reduce execution time `array_merge` can be called only once: | ||
``` php | ||
$options = [[]]; | ||
foreach ($configurationSources as $source) { | ||
// code here | ||
$options[] = $source->getOptions(); | ||
} | ||
|
||
// PHP 5.6+ | ||
$options = array_merge(...$options); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.