optimized a comparison in the tokenizer
authorFabien Potencier <fabien.potencier@gmail.com>
Sun, 30 Oct 2011 22:07:03 +0000 (23:07 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 31 Oct 2011 17:03:19 +0000 (18:03 +0100)
lib/Twig/Lexer.php

index 53a3e80..a365715 100644 (file)
@@ -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 = '';
                 }
             }
         }