From: Scott Reeves Date: Mon, 29 Apr 2013 17:09:58 +0000 (-0400) Subject: Add static caching for Twig_Environment::getTemplateClass() X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=4ae5385d438b84358d307980b8032f737c697df5;p=web%2Fkonrad%2Ftwig.git Add static caching for Twig_Environment::getTemplateClass() --- diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 32b026a..89c5a67 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -44,6 +44,7 @@ class Twig_Environment protected $functionCallbacks; protected $filterCallbacks; protected $staging; + protected $templateClasses; /** * Constructor. @@ -107,6 +108,7 @@ class Twig_Environment $this->setCache($options['cache']); $this->functionCallbacks = array(); $this->filterCallbacks = array(); + $this->templateClasses = array(); $this->addExtension(new Twig_Extension_Core()); $this->addExtension(new Twig_Extension_Escaper($options['autoescape'])); @@ -262,7 +264,12 @@ class Twig_Environment */ public function getTemplateClass($name, $index = null) { - return $this->templateClassPrefix.md5($this->getLoader()->getCacheKey($name)).(null === $index ? '' : '_'.$index); + $suffix = null === $index ? '' : '_'.$index; + $cls = $name.$suffix; + if (!isset($this->templateClasses[$cls])) { + $this->templateClasses[$cls] = $this->templateClassPrefix.md5($this->getLoader()->getCacheKey($name)).$suffix; + } + return $this->templateClasses[$cls]; } /**