Optimize findPackagesWithReplacersAndProviders to avoid multiple loops over replace/provide links
parent
20e4cc3b6f
commit
5b41b78809
|
@ -43,24 +43,24 @@ class InstalledRepository extends CompositeRepository
|
||||||
$matches = array();
|
$matches = array();
|
||||||
foreach ($this->getRepositories() as $repo) {
|
foreach ($this->getRepositories() as $repo) {
|
||||||
foreach ($repo->getPackages() as $candidate) {
|
foreach ($repo->getPackages() as $candidate) {
|
||||||
if (in_array($name, $candidate->getNames(), true)) {
|
if ($name === $candidate->getName()) {
|
||||||
if (null === $constraint) {
|
if (null === $constraint || $constraint->matches(new Constraint('==', $candidate->getVersion()))) {
|
||||||
$matches[] = $candidate;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($name === $candidate->getName() && $constraint->matches(new Constraint('==', $candidate->getVersion()))) {
|
|
||||||
$matches[] = $candidate;
|
$matches[] = $candidate;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (array_merge($candidate->getProvides(), $candidate->getReplaces()) as $link) {
|
foreach (array_merge($candidate->getProvides(), $candidate->getReplaces()) as $link) {
|
||||||
if ($name === $link->getTarget() && ($link->getConstraint() === null || $constraint->matches($link->getConstraint()))) {
|
if (
|
||||||
|
$name === $link->getTarget()
|
||||||
|
&& ($constraint === null || $link->getConstraint() === null || $constraint->matches($link->getConstraint()))
|
||||||
|
) {
|
||||||
$matches[] = $candidate;
|
$matches[] = $candidate;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $matches;
|
return $matches;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue