mirror of
https://github.com/php/php-src.git
synced 2026-10-28 17:56:50 +08:00
[$a, $b] = [$b, $a]; built an array of the values, fetched every element out of it again and freed it. When the result of the assignment is not used, the right side is an array literal and the left side a flat list with a target for every value, assign the values to the targets directly instead. The values are still evaluated in order before the first assignment and a variable among them is copied first. Each target then takes its value, so a value its target does not keep (a setter that drops it, the same variable twice, a typed property that coerces it) is released at that assignment rather than after the last one, and a destructor that throws there stops the rest of the statement. Assignments in the expression lists of a for loop, whose results are not used either, are compiled the same way. Nested lists, keys on either side, references, spread, a different number of values and targets and a used result keep the usual compilation. A swap goes from 922 to 467 instructions per call of a function doing it, below a swap through a temporary variable (493).