optimized filter tag implementation
authorFabien Potencier <fabien.potencier@gmail.com>
Thu, 6 Jan 2011 07:18:55 +0000 (08:18 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Thu, 6 Jan 2011 07:20:09 +0000 (08:20 +0100)
lib/Twig/TokenParser/Filter.php

index 35d3b54..2e0e31c 100644 (file)
@@ -20,23 +20,18 @@ class Twig_TokenParser_Filter extends Twig_TokenParser
     public function parse(Twig_Token $token)
     {
         $name = str_replace('.', '_', uniqid('_tmp_', true));
-        $node = new Twig_Node_Expression_Name($name, $token->getLine());
-
-        $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($node, $this->getTag());
+        $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), $token->getLine(), $this->getTag());
 
+        $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
+
         $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
 
-        $ref = new Twig_Node_BlockReference($name, $token->getLine(), $this->getTag());
-
         $block = new Twig_Node_Block($name, $body, $token->getLine());
         $this->parser->setBlock($name, $block);
 
-        $set = new Twig_Node_Set(true, new Twig_Node(array(new Twig_Node_Expression_AssignName($name, $token->getLine()))), new Twig_Node(array($ref)), $token->getLine(), $this->getTag());
-        $filter = new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
-
-        return new Twig_Node(array($set, $filter));
+        return new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
     }
 
     public function decideBlockEnd($token)