Skip to content

Commit

Permalink
minor twigphp#3936 Remove usage of isset before array_key_exists as p…
Browse files Browse the repository at this point in the history
…erformance is not an issue anymore (fabpot)

This PR was merged into the 4.x branch.

Discussion
----------

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

Commits
-------

c8d6df7 Remove usage of isset before array_key_exists as performance is not an issue anymore
  • Loading branch information
fabpot committed Dec 9, 2023
2 parents a2eb71c + c8d6df7 commit 7e48b0a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/Node/Expression/NameExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public function compile(Compiler $compiler): void
;
} else {
$compiler
->raw('(isset($context[')
->string($name)
->raw(']) || array_key_exists(')
->raw('(array_key_exists(')
->string($name)
->raw(', $context) ? $context[')
->string($name)
Expand Down
2 changes: 1 addition & 1 deletion tests/Node/Expression/NameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getTests()
$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],
Expand Down

0 comments on commit 7e48b0a

Please sign in to comment.