|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace BenchNestedContextSnapshots; |
| 4 | + |
| 5 | +use Countable; |
| 6 | + |
| 7 | +/** |
| 8 | + * Shaped like a compiled Twig template with nested for-loops: every loop |
| 9 | + * stores the whole context in $context['_parent'] and in loop.parent, so |
| 10 | + * the same members are shared by every nesting level, and walking them |
| 11 | + * once per path leading to them is exponential in the depth. |
| 12 | + * |
| 13 | + * @param array{known: int, dynamic: mixed, metadata: array{null, null, null, null, null}} $context |
| 14 | + * @return iterable<mixed> |
| 15 | + */ |
| 16 | +function doDisplay(array $context): iterable |
| 17 | +{ |
| 18 | + yield $context['known']; |
| 19 | + $context['_parent'] = $context; |
| 20 | + $context['_seq'] = range(1, 3); |
| 21 | + $context['loop'] = ['parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true]; |
| 22 | + if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) { |
| 23 | + $length = count($context['_seq']); |
| 24 | + $context['loop']['revindex0'] = $length - 1; |
| 25 | + $context['loop']['revindex'] = $length; |
| 26 | + $context['loop']['length'] = $length; |
| 27 | + $context['loop']['last'] = 1 === $length; |
| 28 | + } |
| 29 | + foreach ($context['_seq'] as $context['_key'] => $context['l1']) { |
| 30 | + yield $context['loop']['index']; |
| 31 | + yield $context['known']; |
| 32 | + $context['_parent'] = $context; |
| 33 | + $context['_seq'] = range(1, 3); |
| 34 | + $context['loop'] = ['parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true]; |
| 35 | + if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) { |
| 36 | + $length = count($context['_seq']); |
| 37 | + $context['loop']['revindex0'] = $length - 1; |
| 38 | + $context['loop']['revindex'] = $length; |
| 39 | + $context['loop']['length'] = $length; |
| 40 | + $context['loop']['last'] = 1 === $length; |
| 41 | + } |
| 42 | + foreach ($context['_seq'] as $context['_key'] => $context['l2']) { |
| 43 | + yield $context['loop']['index']; |
| 44 | + yield $context['known']; |
| 45 | + $context['_parent'] = $context; |
| 46 | + $context['_seq'] = range(1, 3); |
| 47 | + $context['loop'] = ['parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true]; |
| 48 | + if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) { |
| 49 | + $length = count($context['_seq']); |
| 50 | + $context['loop']['revindex0'] = $length - 1; |
| 51 | + $context['loop']['revindex'] = $length; |
| 52 | + $context['loop']['length'] = $length; |
| 53 | + $context['loop']['last'] = 1 === $length; |
| 54 | + } |
| 55 | + foreach ($context['_seq'] as $context['_key'] => $context['l3']) { |
| 56 | + yield $context['loop']['index']; |
| 57 | + yield $context['known']; |
| 58 | + $context['_parent'] = $context; |
| 59 | + $context['_seq'] = range(1, 3); |
| 60 | + $context['loop'] = ['parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true]; |
| 61 | + if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) { |
| 62 | + $length = count($context['_seq']); |
| 63 | + $context['loop']['revindex0'] = $length - 1; |
| 64 | + $context['loop']['revindex'] = $length; |
| 65 | + $context['loop']['length'] = $length; |
| 66 | + $context['loop']['last'] = 1 === $length; |
| 67 | + } |
| 68 | + foreach ($context['_seq'] as $context['_key'] => $context['l4']) { |
| 69 | + yield $context['loop']['index']; |
| 70 | + yield $context['known']; |
| 71 | + $context['_parent'] = $context; |
| 72 | + $context['_seq'] = range(1, 3); |
| 73 | + $context['loop'] = ['parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true]; |
| 74 | + if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) { |
| 75 | + $length = count($context['_seq']); |
| 76 | + $context['loop']['revindex0'] = $length - 1; |
| 77 | + $context['loop']['revindex'] = $length; |
| 78 | + $context['loop']['length'] = $length; |
| 79 | + $context['loop']['last'] = 1 === $length; |
| 80 | + } |
| 81 | + foreach ($context['_seq'] as $context['_key'] => $context['l5']) { |
| 82 | + yield $context['loop']['index']; |
| 83 | + yield $context['known']; |
| 84 | + $context['_parent'] = $context; |
| 85 | + $context['_seq'] = range(1, 3); |
| 86 | + $context['loop'] = ['parent' => $context['_parent'], 'index0' => 0, 'index' => 1, 'first' => true]; |
| 87 | + if (is_array($context['_seq']) || is_object($context['_seq']) && $context['_seq'] instanceof Countable) { |
| 88 | + $length = count($context['_seq']); |
| 89 | + $context['loop']['revindex0'] = $length - 1; |
| 90 | + $context['loop']['revindex'] = $length; |
| 91 | + $context['loop']['length'] = $length; |
| 92 | + $context['loop']['last'] = 1 === $length; |
| 93 | + } |
| 94 | + foreach ($context['_seq'] as $context['_key'] => $context['l6']) { |
| 95 | + yield $context['loop']['index']; |
| 96 | + ++$context['loop']['index0']; |
| 97 | + ++$context['loop']['index']; |
| 98 | + $context['loop']['first'] = false; |
| 99 | + if (isset($context['loop']['revindex0'], $context['loop']['revindex'])) { |
| 100 | + --$context['loop']['revindex0']; |
| 101 | + --$context['loop']['revindex']; |
| 102 | + $context['loop']['last'] = 0 === $context['loop']['revindex0']; |
| 103 | + } |
| 104 | + } |
| 105 | + $_parent = $context['_parent']; |
| 106 | + unset($context['_seq'], $context['_key'], $context['l6'], $context['_parent'], $context['loop']); |
| 107 | + $context = array_intersect_key($context, $_parent) + $_parent; |
| 108 | + ++$context['loop']['index0']; |
| 109 | + ++$context['loop']['index']; |
| 110 | + $context['loop']['first'] = false; |
| 111 | + if (isset($context['loop']['revindex0'], $context['loop']['revindex'])) { |
| 112 | + --$context['loop']['revindex0']; |
| 113 | + --$context['loop']['revindex']; |
| 114 | + $context['loop']['last'] = 0 === $context['loop']['revindex0']; |
| 115 | + } |
| 116 | + } |
| 117 | + $_parent = $context['_parent']; |
| 118 | + unset($context['_seq'], $context['_key'], $context['l5'], $context['_parent'], $context['loop']); |
| 119 | + $context = array_intersect_key($context, $_parent) + $_parent; |
| 120 | + ++$context['loop']['index0']; |
| 121 | + ++$context['loop']['index']; |
| 122 | + $context['loop']['first'] = false; |
| 123 | + if (isset($context['loop']['revindex0'], $context['loop']['revindex'])) { |
| 124 | + --$context['loop']['revindex0']; |
| 125 | + --$context['loop']['revindex']; |
| 126 | + $context['loop']['last'] = 0 === $context['loop']['revindex0']; |
| 127 | + } |
| 128 | + } |
| 129 | + $_parent = $context['_parent']; |
| 130 | + unset($context['_seq'], $context['_key'], $context['l4'], $context['_parent'], $context['loop']); |
| 131 | + $context = array_intersect_key($context, $_parent) + $_parent; |
| 132 | + ++$context['loop']['index0']; |
| 133 | + ++$context['loop']['index']; |
| 134 | + $context['loop']['first'] = false; |
| 135 | + if (isset($context['loop']['revindex0'], $context['loop']['revindex'])) { |
| 136 | + --$context['loop']['revindex0']; |
| 137 | + --$context['loop']['revindex']; |
| 138 | + $context['loop']['last'] = 0 === $context['loop']['revindex0']; |
| 139 | + } |
| 140 | + } |
| 141 | + $_parent = $context['_parent']; |
| 142 | + unset($context['_seq'], $context['_key'], $context['l3'], $context['_parent'], $context['loop']); |
| 143 | + $context = array_intersect_key($context, $_parent) + $_parent; |
| 144 | + ++$context['loop']['index0']; |
| 145 | + ++$context['loop']['index']; |
| 146 | + $context['loop']['first'] = false; |
| 147 | + if (isset($context['loop']['revindex0'], $context['loop']['revindex'])) { |
| 148 | + --$context['loop']['revindex0']; |
| 149 | + --$context['loop']['revindex']; |
| 150 | + $context['loop']['last'] = 0 === $context['loop']['revindex0']; |
| 151 | + } |
| 152 | + } |
| 153 | + $_parent = $context['_parent']; |
| 154 | + unset($context['_seq'], $context['_key'], $context['l2'], $context['_parent'], $context['loop']); |
| 155 | + $context = array_intersect_key($context, $_parent) + $_parent; |
| 156 | + ++$context['loop']['index0']; |
| 157 | + ++$context['loop']['index']; |
| 158 | + $context['loop']['first'] = false; |
| 159 | + if (isset($context['loop']['revindex0'], $context['loop']['revindex'])) { |
| 160 | + --$context['loop']['revindex0']; |
| 161 | + --$context['loop']['revindex']; |
| 162 | + $context['loop']['last'] = 0 === $context['loop']['revindex0']; |
| 163 | + } |
| 164 | + } |
| 165 | + $_parent = $context['_parent']; |
| 166 | + unset($context['_seq'], $context['_key'], $context['l1'], $context['_parent'], $context['loop']); |
| 167 | + $context = array_intersect_key($context, $_parent) + $_parent; |
| 168 | + yield $context['known']; |
| 169 | +} |
0 commit comments