From 27f55cc5673e41d471cffdb26d385a2990b134dc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 1 Apr 2012 10:03:24 +0200 Subject: [PATCH] fixed performance when compiling large files --- CHANGELOG | 1 + lib/Twig/Compiler.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletions(-) 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"); -- 1.7.2.5