Skip to content
Browse files

made a small optimization when a macro does not take any argument

  • Loading branch information...
1 parent d472d21 commit 5446d45f6e310c0287cfd60fe9c9436dab9ade27 @fabpot committed Sep 24, 2011
Showing with 19 additions and 9 deletions.
  1. +19 −9 lib/Twig/Node/Macro.php
View
28 lib/Twig/Node/Macro.php
@@ -38,22 +38,32 @@ public function compile(Twig_Compiler $compiler)
->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()

0 comments on commit 5446d45

Please sign in to comment.
Something went wrong with that request. Please try again.