-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[runtime] add array concat optimization (#979)
The optimization is applied in case at least one of operands is empty. In that case it eliminates copy creation and returns a shared array.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 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
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,51 @@ | ||
@ok | ||
<?php | ||
|
||
function test_array_concat_empty() { | ||
/** @var int[] */ | ||
$arr = [1, 2, 3]; | ||
|
||
/** @var int[] */ | ||
$empty1 = []; | ||
|
||
/** @var int[] */ | ||
$empty2 = []; | ||
|
||
$tmp1 = $arr + $empty1; | ||
$tmp2 = $empty1 + $arr; | ||
$tmp3 = $empty1 + $empty2; | ||
|
||
$arr[0] = -1; | ||
$empty1[0] = -2; | ||
$empty2[0] = -3; | ||
$tmp1[0] = -4; | ||
$tmp2[0] = -5; | ||
$tmp3[0] = -6; | ||
|
||
var_dump($arr); | ||
var_dump($empty1); | ||
var_dump($empty2); | ||
var_dump($tmp1); | ||
var_dump($tmp2); | ||
var_dump($tmp3); | ||
|
||
// ========================================================================== | ||
|
||
$map = ["one" => 1, "two" => 2, "three" => 3]; | ||
|
||
/** @var int[] */ | ||
$empty3 = []; | ||
|
||
$tmp4 = $map + $empty3; | ||
$tmp5 = $empty3 + $map; | ||
|
||
$map["one"] = -1; | ||
$tmp4["one"] = -2; | ||
$tmp5["one"] = -3; | ||
|
||
var_dump($map); | ||
var_dump($tmp4); | ||
var_dump($tmp5); | ||
} | ||
|
||
test_array_concat_empty(); |