mirror of
https://github.com/php/php-src.git
synced 2026-04-28 10:43:30 +02:00
dd4a080133
This makes a number of related changes to the generator tree management, that should hopefully make it easier to understand, more robust and faster for the common linear-chain case. Fixes https://bugs.php.net/bug.php?id=80240, which was the original motivation here. * Generators now only add a ref to their direct parent. * Nodes only store their children, not their leafs, which avoids any need for leaf updating. This means it's no longer possible to fetch the child for a certain leaf, which is something we only needed in one place (update_current). If multi-children nodes are involved, this will require doing a walk in the other direction (from leaf to root). It does not affect the common case of single-child nodes. * The root/leaf pointers are now seen as a pair. One leaf generator can point to the current root. If a different leaf generator is used, we'll move the root pointer over to that one. Again, this is a cache to make the common linear chain case fast, trees may need to scan up the parent link. Closes GH-6344.
33 lines
494 B
PHP
33 lines
494 B
PHP
--TEST--
|
|
Generator backtrace with multi yield from
|
|
--FILE--
|
|
<?php
|
|
|
|
function gen() {
|
|
yield 1;
|
|
debug_print_backtrace();
|
|
yield 2;
|
|
}
|
|
|
|
function from($gen) {
|
|
yield from $gen;
|
|
}
|
|
|
|
$gen1 = gen();
|
|
$gen2 = from($gen1);
|
|
$gen3 = from($gen2);
|
|
var_dump($gen3->current());
|
|
$gen2->next();
|
|
var_dump($gen2->current());
|
|
$gen2->next();
|
|
var_dump($gen2->current());
|
|
|
|
?>
|
|
--EXPECTF--
|
|
int(1)
|
|
int(1)
|
|
#0 gen() called at [%s:10]
|
|
#1 from(Generator Object ())
|
|
#2 Generator->next() called at [%s:19]
|
|
int(2)
|