Remove usage of isset before array_key_exists as performance is not an issue anymore

This commit is contained in:
Fabien Potencier
2020-12-28 11:45:58 +01:00
parent a2eb71ce66
commit c8d6df7eb2
2 changed files with 2 additions and 4 deletions
+1 -3
View File
@@ -60,9 +60,7 @@ class NameExpression extends AbstractExpression
;
} else {
$compiler
->raw('(isset($context[')
->string($name)
->raw(']) || array_key_exists(')
->raw('(array_key_exists(')
->string($name)
->raw(', $context) ? $context[')
->string($name)
+1 -1
View File
@@ -34,7 +34,7 @@ class NameTest extends NodeTestCase
$env = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]);
$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 [
[$node, "// line 1\n".$output, $env],