From dfb523eab6b78dd3ae9297b29abb21a30339daf4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 31 Mar 2012 15:26:42 +0200 Subject: [PATCH] made a small optimization when there is only one trait used in a template --- lib/Twig/Node/Module.php | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-) 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") -- 1.7.2.5