From 4dc490fbd50ca8bd5a6f1c26ddf03c1bfc2abeb3 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Tue, 30 Aug 2011 06:02:31 +0300 Subject: [PATCH] Removing array_shift for optimisation. For example we check if a template and use exception to redirect to a default template Before : We checked ~1000 times => 100sec due to array_shift After : ~1sec --- lib/Twig/Error.php | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index d6946f0..5659e85 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -175,7 +175,10 @@ class Twig_Error extends Exception $tokens = token_get_all(file_get_contents($r->getFilename())); $templateline = -1; $template = null; - while ($token = array_shift($tokens)) { + $tokensSize = count($tokens); + for($j = 0; $j < $tokensSize; $j++) { + $token = $tokens[$j]; + if (isset($token[2]) && $token[2] >= $line) { return array($templateline, $template); } -- 1.7.2.5