Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't instantiate a LambdaHelper for classes with no Lambdas :)

  • Loading branch information...
commit 05e527fe212cd1d305e557d82eef16b06a250bea 1 parent 38453d0
@bobthecow authored
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/Mustache/Compiler.php
View
21 src/Mustache/Compiler.php
@@ -141,6 +141,24 @@ public function renderInternal(Mustache_Context $context, $indent = \'\', $escap
%s
}';
+ const KLASS_NO_LAMBDAS = '<?php
+
+ class %s extends Mustache_Template
+ {
+ public function renderInternal(Mustache_Context $context, $indent = \'\', $escape = false)
+ {
+ $buffer = \'\';
+ %s
+
+ if ($escape) {
+ return %s;
+ } else {
+ return $buffer;
+ }
+ }
+ %s
+ }';
+
/**
* Generate Mustache Template class PHP source.
*
@@ -153,8 +171,9 @@ private function writeCode($tree, $name)
{
$code = $this->walk($tree);
$sections = implode("\n", $this->sections);
+ $klass = empty($this->sections) ? self::KLASS_NO_LAMBDAS : self::KLASS;
- return sprintf($this->prepare(self::KLASS, 0, false), $name, $code, $this->getEscape('$buffer'), $sections);
+ return sprintf($this->prepare($klass, 0, false), $name, $code, $this->getEscape('$buffer'), $sections);
}
const SECTION_CALL = '
Please sign in to comment.
Something went wrong with that request. Please try again.