made a small optimization when there is only one trait used in a template
authorFabien Potencier <fabien.potencier@gmail.com>
Sat, 31 Mar 2012 13:26:42 +0000 (15:26 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Sat, 31 Mar 2012 13:26:42 +0000 (15:26 +0200)
lib/Twig/Node/Module.php

index eb60c42..c67bc9a 100644 (file)
@@ -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")