Permalink
Browse files

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
  • Loading branch information...
1 parent 543d18b commit 4dc490fbd50ca8bd5a6f1c26ddf03c1bfc2abeb3 @joelwurtz joelwurtz committed Aug 30, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/Twig/Error.php
View
@@ -175,7 +175,10 @@ protected function findTemplateInfo(Exception $e, $currentLine, $currentFile)
$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);
}

0 comments on commit 4dc490f

Please sign in to comment.