mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
Remove usage of isset before array_key_exists as performance is not an issue anymore
This commit is contained in:
@@ -60,9 +60,7 @@ class NameExpression extends AbstractExpression
|
|||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
$compiler
|
$compiler
|
||||||
->raw('(isset($context[')
|
->raw('(array_key_exists(')
|
||||||
->string($name)
|
|
||||||
->raw(']) || array_key_exists(')
|
|
||||||
->string($name)
|
->string($name)
|
||||||
->raw(', $context) ? $context[')
|
->raw(', $context) ? $context[')
|
||||||
->string($name)
|
->string($name)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class NameTest extends NodeTestCase
|
|||||||
$env = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]);
|
$env = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]);
|
||||||
$env1 = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => false]);
|
$env1 = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => false]);
|
||||||
|
|
||||||
$output = '(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : throw new RuntimeError(\'Variable "foo" does not exist.\', 1, $this->source))';
|
$output = '(array_key_exists("foo", $context) ? $context["foo"] : throw new RuntimeError(\'Variable "foo" does not exist.\', 1, $this->source))';
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[$node, "// line 1\n".$output, $env],
|
[$node, "// line 1\n".$output, $env],
|
||||||
|
|||||||
Reference in New Issue
Block a user