Explorar el Código

Speed up Pool::match for common case

Jordi Boggiano hace 12 años
padre
commit
6f77df296a
Se han modificado 1 ficheros con 11 adiciones y 7 borrados
  1. 11 7
      src/Composer/DependencyResolver/Pool.php

+ 11 - 7
src/Composer/DependencyResolver/Pool.php

@@ -339,6 +339,17 @@ class Pool
         if (is_array($candidate)) {
             $candidateName = $candidate['name'];
             $candidateVersion = $candidate['version'];
+        } else {
+            // handle object packages
+            $candidateName = $candidate->getName();
+            $candidateVersion = $candidate->getVersion();
+        }
+
+        if ($candidateName === $name) {
+            return $constraint->matches(new VersionConstraint('==', $candidateVersion)) ? self::MATCH : self::MATCH_NAME;
+        }
+
+        if (is_array($candidate)) {
             $provides = isset($candidate['provide'])
                 ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'provides', $candidate['provide'])
                 : array();
@@ -346,17 +357,10 @@ class Pool
                 ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'replaces', $candidate['replace'])
                 : array();
         } else {
-            // handle object packages
-            $candidateName = $candidate->getName();
-            $candidateVersion = $candidate->getVersion();
             $provides = $candidate->getProvides();
             $replaces = $candidate->getReplaces();
         }
 
-        if ($candidateName === $name) {
-            return $constraint->matches(new VersionConstraint('==', $candidateVersion)) ? self::MATCH : self::MATCH_NAME;
-        }
-
         foreach ($provides as $link) {
             if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
                 return self::MATCH_PROVIDE;