From: Fabien Potencier Date: Sun, 1 Apr 2012 08:03:24 +0000 (+0200) Subject: fixed performance when compiling large files X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=27f55cc5673e41d471cffdb26d385a2990b134dc;p=web%2Fkonrad%2Ftwig.git fixed performance when compiling large files --- diff --git a/CHANGELOG b/CHANGELOG index 9b4c198..a8e1ca0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index 656b030..ae415a2 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -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");