1
0
Fork 0

Speed up Pool::match for common case

pull/1015/head
Jordi Boggiano 2012-08-24 16:46:08 +02:00
parent c97720c607
commit 6f77df296a
1 changed files with 11 additions and 7 deletions

View File

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