From: Fabien Potencier Date: Fri, 3 Dec 2010 17:35:29 +0000 (+0100) Subject: made a speed optimization in Lexer X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=67452dbe73af1be9d7565d483b6a1ce3f8c313c7;p=web%2Fkonrad%2Ftwig.git made a speed optimization in Lexer --- diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 2803824..e405be5 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -51,11 +51,6 @@ class Twig_Lexer implements Twig_LexerInterface ), $options); } - public function sortByLength($a, $b) - { - return strlen($a) > strlen($b) ? -1 : 1; - } - /** * Tokenizes a source code. * @@ -336,10 +331,12 @@ class Twig_Lexer implements Twig_LexerInterface $operators = array('='); $operators = array_merge($operators, array_keys($this->env->getUnaryOperators())); $operators = array_merge($operators, array_keys($this->env->getBinaryOperators())); - usort($operators, array($this, 'sortByLength')); + + $operators = array_combine($operators, array_map('strlen', $operators)); + arsort($operators); $regex = array(); - foreach ($operators as $operator) { + foreach (array_keys($operators) as $operator) { $last = ord(substr($operator, -1)); // an operator that ends with a character must be followed by // a whitespace or a parenthese