From: Fabien Potencier Date: Sun, 30 Oct 2011 22:07:03 +0000 (+0100) Subject: optimized a comparison in the tokenizer X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=4b115d458f3097db7550a37c8e0cc9263b664c59;p=web%2Fkonrad%2Ftwig.git optimized a comparison in the tokenizer --- diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 53a3e80..a365715 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -118,19 +118,21 @@ class Twig_Lexer implements Twig_LexerInterface protected function lexData() { $pos = $this->end; + $trimBlock = false; $append = ''; // Find the first token after the cursor foreach (array('tag_comment', 'tag_variable', 'tag_block') as $type) { $tmpPos = strpos($this->code, $this->options[$type][0], $this->cursor); if (false !== $tmpPos && $tmpPos < $pos) { - $trimBlock = false; - $append = ''; $pos = $tmpPos; $token = $this->options[$type][0]; - if (strpos($this->code, $this->options['whitespace_trim'], $pos) === ($pos + strlen($token))) { + if ($this->options['whitespace_trim'] === substr($this->code, $pos + strlen($token), strlen($this->options['whitespace_trim']))) { $trimBlock = true; $append = $this->options['whitespace_trim']; + } else { + $trimBlock = false; + $append = ''; } } }