From: Fabien Potencier Date: Sat, 31 Mar 2012 13:26:42 +0000 (+0200) Subject: made a small optimization when there is only one trait used in a template X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=dfb523eab6b78dd3ae9297b29abb21a30339daf4;p=web%2Fkonrad%2Ftwig.git made a small optimization when there is only one trait used in a template --- diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index eb60c42..c67bc9a 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -168,20 +168,29 @@ class Twig_Node_Module extends Twig_Node } } - $compiler - ->write("\$this->traits = array_merge(\n") - ->indent() - ; + if ($countTraits > 1) { + $compiler + ->write("\$this->traits = array_merge(\n") + ->indent() + ; + + for ($i = 0; $i < $countTraits; $i++) { + $compiler + ->write(sprintf("\$_trait_%s_blocks".($i == $countTraits - 1 ? '' : ',')."\n", $i)) + ; + } - for ($i = 0; $i < $countTraits; $i++) { $compiler - ->write(sprintf("\$_trait_%s_blocks".($i == $countTraits - 1 ? '' : ',')."\n", $i)) + ->outdent() + ->write(");\n\n") + ; + } else { + $compiler + ->write("\$this->traits = \$_trait_0_blocks;\n\n") ; } $compiler - ->outdent() - ->write(");\n\n") ->write("\$this->blocks = array_merge(\n") ->indent() ->write("\$this->traits,\n")