Permalink
Browse files

merged branch nikic/improveIsDefinedPerformanceInNonStrictMode (PR #381)

Commits
-------

e4b8371 Improve performance of is defined in non strict mode

Discussion
----------

Improve performance of is defined in non strict mode

Addresses issue #380: This gives a good performance improvement on defined tests in non-strict code. About 2x.

Reasoning: It doesn't make sense to propagate the `is_defined_test` flag into deeper levels in non-strict mode, because all getAttr functions and name accesses will just return `null` if it doesn't exist and `null` is just as good as `false`.

---------------------------------------------------------------------------

by nikic at 2011/07/02 03:22:53 -0700

Though, do not merge yet please. Changes behavior concerning methods.

---------------------------------------------------------------------------

by nikic at 2011/07/02 13:34:32 -0700

Hm, I really don't know what I was thinking when I wrote my last comment. There shouldn't be any behavior changes introduced by that change (and tests pass).
  • Loading branch information...
2 parents 0ef96f6 + e4b8371 commit 90d99a7737270b2720b8ba88a9ad70dedade9cd5 @fabpot committed Jul 12, 2011
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/Twig/Node/Expression/GetAttr.php
@@ -20,7 +20,9 @@ public function compile(Twig_Compiler $compiler)
{
$compiler->raw('$this->getAttribute(');
- if ($this->hasAttribute('is_defined_test')) {
+ if ($this->hasAttribute('is_defined_test')
+ && $compiler->getEnvironment()->isStrictVariables()
+ ) {
$compiler->subcompile(new Twig_Node_Expression_Filter(
$this->getNode('node'),
new Twig_Node_Expression_Constant('default', $this->getLine()),

0 comments on commit 90d99a7

Please sign in to comment.