浏览代码

[ClassLoader] made a big performance improvement

Fabien Potencier 14 年之前
父节点
当前提交
fb4f37856e
共有 1 个文件被更改,包括 4 次插入3 次删除
  1. 4 3
      src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

+ 4 - 3
src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

@@ -135,7 +135,8 @@ class ClassCollectionLoader
         $inNamespace = false;
         $tokens = token_get_all($source);
 
-        while ($token = array_shift($tokens)) {
+        for ($i = 0, $max = count($tokens); $i < $max; $i++) {
+            $token = $tokens[$i];
             if (is_string($token)) {
                 $output .= $token;
             } elseif (T_NAMESPACE === $token[0]) {
@@ -145,12 +146,12 @@ class ClassCollectionLoader
                 $output .= $token[1];
 
                 // namespace name and whitespaces
-                while (($t = array_shift($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
+                while (($t = $tokens[++$i]) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
                     $output .= $t[1];
                 }
                 if (is_string($t) && '{' === $t) {
                     $inNamespace = false;
-                    array_unshift($tokens, $t);
+                    --$i;
                 } else {
                     $output .= "\n{";
                     $inNamespace = true;