fixed performance when compiling large files

This commit is contained in:
Fabien Potencier
2012-04-01 10:03:24 +02:00
parent dfb523eab6
commit 27f55cc567
2 changed files with 8 additions and 1 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.6.4 (2012-XX-XX)
* fixed performance when compiling large files
* optimized parent template creation when the template does not use dynamic inheritance
* 1.6.3 (2012-03-22)
+7 -1
View File
@@ -23,6 +23,8 @@ class Twig_Compiler implements Twig_CompilerInterface
protected $indentation;
protected $env;
protected $debugInfo;
protected $sourceOffset;
protected $sourceLine;
/**
* Constructor.
@@ -67,6 +69,8 @@ class Twig_Compiler implements Twig_CompilerInterface
{
$this->lastLine = null;
$this->source = '';
$this->sourceOffset = 0;
$this->sourceLine = 0;
$this->indentation = $indentation;
$node->compile($this);
@@ -188,7 +192,9 @@ class Twig_Compiler implements Twig_CompilerInterface
public function addDebugInfo(Twig_NodeInterface $node)
{
if ($node->getLine() != $this->lastLine) {
$this->debugInfo[substr_count($this->source, "\n")] = $node->getLine();
$this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
$this->sourceOffset = strlen($this->source);
$this->debugInfo[$this->sourceLine] = $node->getLine();
$this->lastLine = $node->getLine();
$this->write("// line {$node->getLine()}\n");