mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-08 00:17:29 +00:00
Make some small internal tweaks to loops
This commit is contained in:
@@ -65,7 +65,7 @@ class ForNode extends Node
|
||||
|
||||
if ($this->hasNode('else')) {
|
||||
$compiler
|
||||
->write("if (!\${$loopName}->iterated()) {\n")
|
||||
->write("if (0 === \${$loopName}->getIndex0()) {\n")
|
||||
->indent()
|
||||
->subcompile($this->getNode('else'))
|
||||
->outdent()
|
||||
|
||||
@@ -22,8 +22,10 @@ final class LoopContext
|
||||
{
|
||||
private mixed $lastChanged;
|
||||
|
||||
public function __construct(private LoopIterator $loop, private $parent)
|
||||
{
|
||||
public function __construct(
|
||||
private LoopIterator $loop,
|
||||
private $parent,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getParent(): mixed
|
||||
@@ -63,7 +65,7 @@ final class LoopContext
|
||||
|
||||
public function isLast(): bool
|
||||
{
|
||||
return $this->loop->isLast();
|
||||
return !$this->loop->getNext()['valid'];
|
||||
}
|
||||
|
||||
public function hasChanged(mixed $value): bool
|
||||
|
||||
@@ -90,11 +90,6 @@ final class LoopIterator implements \Iterator
|
||||
return $this->current['valid'];
|
||||
}
|
||||
|
||||
public function iterated(): bool
|
||||
{
|
||||
return 0 !== $this->index0;
|
||||
}
|
||||
|
||||
public function getIndex0(): int
|
||||
{
|
||||
return $this->index0;
|
||||
@@ -113,11 +108,6 @@ final class LoopIterator implements \Iterator
|
||||
return $this->length = count($this->seq);
|
||||
}
|
||||
|
||||
public function isLast(): bool
|
||||
{
|
||||
return !$this->getNext()['valid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{valid: bool, key: mixed, value: mixed}
|
||||
*/
|
||||
|
||||
@@ -127,7 +127,7 @@ EOF
|
||||
foreach (\$__internal_compile_0 as \$context["k"] => \$context["v"]) {
|
||||
yield {$this->getVariableGetter('foo')};
|
||||
}
|
||||
if (!\$__internal_compile_0->iterated()) {
|
||||
if (0 === \$__internal_compile_0->getIndex0()) {
|
||||
yield {$this->getVariableGetter('foo')};
|
||||
}
|
||||
\$_parent = \$context['_parent'];
|
||||
|
||||
Reference in New Issue
Block a user