1
0
Fork 0

Optimize findPackagesWithReplacersAndProviders to avoid multiple loops over replace/provide links

pull/8669/head
Jordi Boggiano 2020-02-18 08:10:54 +01:00
parent 20e4cc3b6f
commit 5b41b78809
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 12 additions and 12 deletions

View File

@ -43,21 +43,21 @@ class InstalledRepository extends CompositeRepository
$matches = array();
foreach ($this->getRepositories() as $repo) {
foreach ($repo->getPackages() as $candidate) {
if (in_array($name, $candidate->getNames(), true)) {
if (null === $constraint) {
if ($name === $candidate->getName()) {
if (null === $constraint || $constraint->matches(new Constraint('==', $candidate->getVersion()))) {
$matches[] = $candidate;
}
continue;
}
foreach (array_merge($candidate->getProvides(), $candidate->getReplaces()) as $link) {
if (
$name === $link->getTarget()
&& ($constraint === null || $link->getConstraint() === null || $constraint->matches($link->getConstraint()))
) {
$matches[] = $candidate;
continue;
}
if ($name === $candidate->getName() && $constraint->matches(new Constraint('==', $candidate->getVersion()))) {
$matches[] = $candidate;
continue;
}
foreach (array_merge($candidate->getProvides(), $candidate->getReplaces()) as $link) {
if ($name === $link->getTarget() && ($link->getConstraint() === null || $constraint->matches($link->getConstraint()))) {
$matches[] = $candidate;
continue;
}
}
}
}
}