Permalink
Browse files

made a small optimization when there is only one trait used in a temp…

…late
  • Loading branch information...
1 parent 1e9a1ae commit dfb523eab6b78dd3ae9297b29abb21a30339daf4 @fabpot committed Mar 31, 2012
Showing with 17 additions and 8 deletions.
  1. +17 −8 lib/Twig/Node/Module.php
View
@@ -168,20 +168,29 @@ protected function compileConstructor(Twig_Compiler $compiler)
}
}
- $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")

0 comments on commit dfb523e

Please sign in to comment.