From 4b115d458f3097db7550a37c8e0cc9263b664c59 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 30 Oct 2011 23:07:03 +0100 Subject: [PATCH] optimized a comparison in the tokenizer --- lib/Twig/Lexer.php | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) 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 = ''; } } } -- 1.7.2.5