Closed as not planned
Description
Description
code patterns like:
$res = [];
foreach ($items as $item) {
$res = array_merge($res, $this->getData($item));
}
are very common and as shown in the 3v4l fiddle the code can run much faster if php will optimize array_merge
function using this algorithm:
- if
array_merge
is internal (not replaced/custom) function - choose the argument with the most elements/count
- use such argument by reference and merge the other arguments into it
this optimization can reduce the complexity from O(n) to O(1) in extreme case (1 argument with many elements and 1 argument with 1 element)
same optimization should be done for spread operator as well
related #9794 and https://bugs.php.net/bug.php?id=72492