rfc:loop_default
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:loop_default [2014/09/19 07:59] – created leigh | rfc:loop_default [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 26: | Line 26: | ||
} | } | ||
- | for ($i = 0, $j = $k; $i < 4 && $j < 65536; $i++, $j >>= 1) { | + | for ($i = 0, $j = $k; $i < 4 && $j < 65536; $i++, $j <<= 1) { |
// loop body | // loop body | ||
} | } | ||
Line 41: | Line 41: | ||
</ | </ | ||
+ | In the case of '' | ||
- | This kind of behaviour has been suggested before using the '' | + | '' |
- | Not backwards compatible by default due to dangling '' | + | Alternate syntax loops also gain this functionality with a '' |
+ | |||
+ | This type of behaviour has been suggested before usually using the '' | ||
+ | |||
+ | | ||
<code php> | <code php> | ||
if ($something) | if ($something) | ||
Line 53: | Line 58: | ||
</ | </ | ||
- | Making it backwards compatible leads to inconsistent behaviour | + | |
<code php> | <code php> | ||
if ($something) | if ($something) | ||
Line 62: | Line 67: | ||
</ | </ | ||
- | It breaks familiarity with similar behaviour in other languages | + | |
<code php> | <code php> | ||
while ($cond) { | while ($cond) { | ||
Line 76: | Line 81: | ||
The intention is to implement this by duplicating loop prologues to avoid the requirement for tracking variables, and keep performance on-par with pre-patch looping. | The intention is to implement this by duplicating loop prologues to avoid the requirement for tracking variables, and keep performance on-par with pre-patch looping. | ||
- | Pre-patch basic while loop. | + | As an example here is the opcode dump of a pre-patch basic while loop. |
< | < | ||
+ | $i = 3; | ||
+ | while ($i--) { | ||
+ | print ' | ||
+ | } | ||
+ | |||
line # * op | line # * op | ||
--------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ||
Line 89: | Line 99: | ||
</ | </ | ||
- | Post-patch basic while loop with default block (labels added to help visualise flow) | + | And a post-patch basic while loop with default block (labels added to help visualise flow) |
< | < | ||
+ | $i = 0; | ||
+ | while ($i--) { | ||
+ | print ' | ||
+ | } | ||
+ | default { | ||
+ | print ' | ||
+ | } | ||
+ | |||
# * op | # * op | ||
--------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ||
- | | + | |
cond_1: | cond_1: | ||
| | ||
Line 106: | Line 124: | ||
</ | </ | ||
- | The key here is that '' | + | The key here is that '' |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 131: | Line 149: | ||
Both require the loop to be entered to have an effect, which means the default block cannot be executed at the point these constructs are used. | Both require the loop to be entered to have an effect, which means the default block cannot be executed at the point these constructs are used. | ||
- | |||
- | Alternate syntax loops also continue to function as expected with a '' | ||
Loops without bodies also get to have default blocks | Loops without bodies also get to have default blocks | ||
Line 143: | Line 159: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | A proof of concept is being worked on by Leigh | + | A proof of concept is being worked on by Leigh - '' |
===== Implementation ===== | ===== Implementation ===== |
rfc/loop_default.1411113578.txt.gz · Last modified: 2017/09/22 13:28 (external edit)