made a speed optimization for template inclusion and when including the same template over and over again

git-svn-id: http://svn.twig-project.org/trunk@84 93ef8e89-cb99-4229-a87c-7fa0fa45744b
This commit is contained in:
fabien
2009-10-20 12:00:02 +00:00
parent fc798571f9
commit b12d2f3df3
2 changed files with 26 additions and 7 deletions
+26 -6
View File
@@ -25,6 +25,8 @@ class Twig_Environment
protected $parsers;
protected $transformers;
protected $filters;
protected $runtimeInitialized;
protected $loadedTemplates;
public function __construct(Twig_LoaderInterface $loader = null, $options = array())
{
@@ -33,11 +35,12 @@ class Twig_Environment
$this->setLoader($loader);
}
$this->debug = isset($options['debug']) ? (bool) $options['debug'] : false;
$this->trimBlocks = isset($options['trim_blocks']) ? (bool) $options['trim_blocks'] : false;
$this->charset = isset($options['charset']) ? $options['charset'] : 'UTF-8';
$this->baseTemplateClass = isset($options['base_template_class']) ? $options['base_template_class'] : 'Twig_Template';
$this->extensions = array(new Twig_Extension_Core());
$this->debug = isset($options['debug']) ? (bool) $options['debug'] : false;
$this->trimBlocks = isset($options['trim_blocks']) ? (bool) $options['trim_blocks'] : false;
$this->charset = isset($options['charset']) ? $options['charset'] : 'UTF-8';
$this->baseTemplateClass = isset($options['base_template_class']) ? $options['base_template_class'] : 'Twig_Template';
$this->extensions = array(new Twig_Extension_Core());
$this->runtimeInitialized = false;
}
public function getBaseTemplateClass()
@@ -77,9 +80,26 @@ class Twig_Environment
public function loadTemplate($name)
{
if (!$this->runtimeInitialized)
{
$this->initRuntime();
$this->runtimeInitialized = true;
}
if (isset($this->loadedTemplates[$name]))
{
return $this->loadedTemplates[$name];
}
$cls = $this->getLoader()->load($name, $this);
return new $cls($this);
return $this->loadedTemplates[$name] = new $cls($this);
}
public function clearTemplateCache()
{
$this->loadedTemplates = array();
}
public function getLexer()
-1
View File
@@ -148,7 +148,6 @@ class Twig_Node_Module extends Twig_Node implements Twig_NodeListInterface
}
$compiler
->write("\$this->env->initRuntime();\n\n")
->subcompile($this->body)
->outdent()
->write("}\n\n")