From 5446d45f6e310c0287cfd60fe9c9436dab9ade27 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 24 Sep 2011 14:20:57 +0200 Subject: [PATCH] made a small optimization when a macro does not take any argument --- lib/Twig/Node/Macro.php | 28 +++++++++++++++++++--------- 1 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 9f95570..be74726 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -38,22 +38,32 @@ class Twig_Node_Macro extends Twig_Node ->addDebugInfo($this) ->write(sprintf("public function get%s(%s)\n", $this->getAttribute('name'), implode(', ', $arguments)), "{\n") ->indent() - ->write("\$context = array_merge(\$this->env->getGlobals(), array(\n") - ->indent() ; - foreach ($this->getNode('arguments') as $argument) { + if (!count($this->getNode('arguments'))) { + $compiler->write("\$context = \$this->env->getGlobals();\n\n"); + } else { $compiler - ->write('') - ->string($argument->getAttribute('name')) - ->raw(' => $'.$argument->getAttribute('name')) - ->raw(",\n") + ->write("\$context = array_merge(\$this->env->getGlobals(), array(\n") + ->indent() + ; + + foreach ($this->getNode('arguments') as $argument) { + $compiler + ->write('') + ->string($argument->getAttribute('name')) + ->raw(' => $'.$argument->getAttribute('name')) + ->raw(",\n") + ; + } + + $compiler + ->outdent() + ->write("));\n\n") ; } $compiler - ->outdent() - ->write("));\n\n") ->write("ob_start();\n") ->write("try {\n") ->indent() -- 1.7.2.5