Преглед на файлове

merged branch Taluu/patch-1 (PR #1942)

Commits
-------

7ec533e got an if-condition out of unnecessary loops in Symfony\Component\ClassLoader\UniversalClassLoader

Discussion
----------

[ClassLoader] Optimization: conditions that do not belong in some loops

Why are these foreachs outside the condition of verification of the namespace?

Should not it be better that the conditions are outside of these foreachs, since these conditions will always return the same result for any item covered by these foreachs?

Cheers
Fabien Potencier преди 13 години
родител
ревизия
4dd599ce06
променени са 1 файла, в които са добавени 4 реда и са изтрити 4 реда
  1. 4 4
      src/Symfony/Component/ClassLoader/UniversalClassLoader.php

+ 4 - 4
src/Symfony/Component/ClassLoader/UniversalClassLoader.php

@@ -220,8 +220,8 @@ class UniversalClassLoader
             // namespaced class name
             $namespace = substr($class, 0, $pos);
             foreach ($this->namespaces as $ns => $dirs) {
-                foreach ($dirs as $dir) {
-                    if (0 === strpos($namespace, $ns)) {
+                if (0 === strpos($namespace, $ns)) {
+                    foreach ($dirs as $dir) {
                         $className = substr($class, $pos + 1);
                         $file = $dir.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
                         if (file_exists($file)) {
@@ -240,8 +240,8 @@ class UniversalClassLoader
         } else {
             // PEAR-like class name
             foreach ($this->prefixes as $prefix => $dirs) {
-                foreach ($dirs as $dir) {
-                    if (0 === strpos($class, $prefix)) {
+                if (0 === strpos($class, $prefix)) {
+                    foreach ($dirs as $dir) {
                         $file = $dir.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
                         if (file_exists($file)) {
                             return $file;