Merge pull request #2734 from naderman/optimize-solver
Optimize the solver and remove unnecessary codepull/3442/head
commit
9e6cfaa3fe
|
@ -45,6 +45,7 @@ class Pool
|
||||||
protected $providerRepos = array();
|
protected $providerRepos = array();
|
||||||
protected $packages = array();
|
protected $packages = array();
|
||||||
protected $packageByName = array();
|
protected $packageByName = array();
|
||||||
|
protected $packageByExactName = array();
|
||||||
protected $acceptableStabilities;
|
protected $acceptableStabilities;
|
||||||
protected $stabilityFlags;
|
protected $stabilityFlags;
|
||||||
protected $versionParser;
|
protected $versionParser;
|
||||||
|
@ -122,6 +123,7 @@ class Pool
|
||||||
$package['id'] = $this->id++;
|
$package['id'] = $this->id++;
|
||||||
$package['stability'] = $stability;
|
$package['stability'] = $stability;
|
||||||
$this->packages[] = $package;
|
$this->packages[] = $package;
|
||||||
|
$this->packageByExactName[$package->getName()][$package['id']] = $this->packages[$this->id - 2];
|
||||||
|
|
||||||
foreach ($names as $provided) {
|
foreach ($names as $provided) {
|
||||||
$this->packageByName[$provided][$package['id']] = $this->packages[$this->id - 2];
|
$this->packageByName[$provided][$package['id']] = $this->packages[$this->id - 2];
|
||||||
|
@ -144,6 +146,7 @@ class Pool
|
||||||
$alias['id'] = $this->id++;
|
$alias['id'] = $this->id++;
|
||||||
$alias['root_alias'] = true;
|
$alias['root_alias'] = true;
|
||||||
$this->packages[] = $alias;
|
$this->packages[] = $alias;
|
||||||
|
$this->packageByExactName[$package->getName()][$alias['id']] = $this->packages[$this->id - 2];
|
||||||
|
|
||||||
foreach ($names as $provided) {
|
foreach ($names as $provided) {
|
||||||
$this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
|
$this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
|
||||||
|
@ -159,6 +162,7 @@ class Pool
|
||||||
$alias['alias_of'] = $package['id'];
|
$alias['alias_of'] = $package['id'];
|
||||||
$alias['id'] = $this->id++;
|
$alias['id'] = $this->id++;
|
||||||
$this->packages[] = $alias;
|
$this->packages[] = $alias;
|
||||||
|
$this->packageByExactName[$package->getName()][$alias['id']] = $this->packages[$this->id - 2];
|
||||||
|
|
||||||
foreach ($names as $provided) {
|
foreach ($names as $provided) {
|
||||||
$this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
|
$this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
|
||||||
|
@ -173,6 +177,7 @@ class Pool
|
||||||
if ($exempt || $this->isPackageAcceptable($names, $stability)) {
|
if ($exempt || $this->isPackageAcceptable($names, $stability)) {
|
||||||
$package->setId($this->id++);
|
$package->setId($this->id++);
|
||||||
$this->packages[] = $package;
|
$this->packages[] = $package;
|
||||||
|
$this->packageByExactName[$package->getName()][$package->getId()] = $package;
|
||||||
|
|
||||||
foreach ($names as $provided) {
|
foreach ($names as $provided) {
|
||||||
$this->packageByName[$provided][] = $package;
|
$this->packageByName[$provided][] = $package;
|
||||||
|
@ -191,6 +196,7 @@ class Pool
|
||||||
|
|
||||||
$package->getRepository()->addPackage($aliasPackage);
|
$package->getRepository()->addPackage($aliasPackage);
|
||||||
$this->packages[] = $aliasPackage;
|
$this->packages[] = $aliasPackage;
|
||||||
|
$this->packageByExactName[$aliasPackage->getName()][$aliasPackage->getId()] = $aliasPackage;
|
||||||
|
|
||||||
foreach ($aliasPackage->getNames() as $name) {
|
foreach ($aliasPackage->getNames() as $name) {
|
||||||
$this->packageByName[$name][] = $aliasPackage;
|
$this->packageByName[$name][] = $aliasPackage;
|
||||||
|
@ -261,7 +267,14 @@ class Pool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->packageByName[$name])) {
|
if ($mustMatchName) {
|
||||||
|
$candidates = array_filter($candidates, function ($candidate) use ($name) {
|
||||||
|
return $candidate->getName() == $name;
|
||||||
|
});
|
||||||
|
if (isset($this->packageByExactName[$name])) {
|
||||||
|
$candidates = array_merge($candidates, $this->packageByExactName[$name]);
|
||||||
|
}
|
||||||
|
} elseif (isset($this->packageByName[$name])) {
|
||||||
$candidates = array_merge($candidates, $this->packageByName[$name]);
|
$candidates = array_merge($candidates, $this->packageByName[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,12 +326,6 @@ class Pool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mustMatchName) {
|
|
||||||
return array_filter($matches, function ($match) use ($name) {
|
|
||||||
return $match->getName() == $name;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a package with the required name exists, we ignore providers
|
// if a package with the required name exists, we ignore providers
|
||||||
if ($nameMatch) {
|
if ($nameMatch) {
|
||||||
return $matches;
|
return $matches;
|
||||||
|
|
|
@ -263,30 +263,6 @@ class RuleSetGenerator
|
||||||
return $impossible;
|
return $impossible;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds all rules for all update packages of a given package
|
|
||||||
*
|
|
||||||
* @param PackageInterface $package Rules for this package's updates are to
|
|
||||||
* be added
|
|
||||||
*/
|
|
||||||
private function addRulesForUpdatePackages(PackageInterface $package, $ignorePlatformReqs)
|
|
||||||
{
|
|
||||||
$updates = $this->policy->findUpdatePackages($this->pool, $this->installedMap, $package);
|
|
||||||
|
|
||||||
foreach ($updates as $update) {
|
|
||||||
$this->addRulesForPackage($update, $ignorePlatformReqs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function whitelistFromUpdatePackages(PackageInterface $package)
|
|
||||||
{
|
|
||||||
$updates = $this->policy->findUpdatePackages($this->pool, $this->installedMap, $package, true);
|
|
||||||
|
|
||||||
foreach ($updates as $update) {
|
|
||||||
$this->whitelistFromPackage($update);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function whitelistFromJobs()
|
protected function whitelistFromJobs()
|
||||||
{
|
{
|
||||||
foreach ($this->jobs as $job) {
|
foreach ($this->jobs as $job) {
|
||||||
|
@ -344,7 +320,6 @@ class RuleSetGenerator
|
||||||
$this->whitelistedMap = array();
|
$this->whitelistedMap = array();
|
||||||
foreach ($this->installedMap as $package) {
|
foreach ($this->installedMap as $package) {
|
||||||
$this->whitelistFromPackage($package);
|
$this->whitelistFromPackage($package);
|
||||||
$this->whitelistFromUpdatePackages($package);
|
|
||||||
}
|
}
|
||||||
$this->whitelistFromJobs();
|
$this->whitelistFromJobs();
|
||||||
|
|
||||||
|
@ -353,7 +328,6 @@ class RuleSetGenerator
|
||||||
$this->addedMap = array();
|
$this->addedMap = array();
|
||||||
foreach ($this->installedMap as $package) {
|
foreach ($this->installedMap as $package) {
|
||||||
$this->addRulesForPackage($package, $ignorePlatformReqs);
|
$this->addRulesForPackage($package, $ignorePlatformReqs);
|
||||||
$this->addRulesForUpdatePackages($package, $ignorePlatformReqs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addRulesForJobs($ignorePlatformReqs);
|
$this->addRulesForJobs($ignorePlatformReqs);
|
||||||
|
|
|
@ -381,25 +381,6 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($version['provide']) || isset($version['replace'])) {
|
|
||||||
// collect names
|
|
||||||
$names = array(
|
|
||||||
strtolower($version['name']) => true,
|
|
||||||
);
|
|
||||||
if (isset($version['provide'])) {
|
|
||||||
foreach ($version['provide'] as $target => $constraint) {
|
|
||||||
$names[strtolower($target)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($version['replace'])) {
|
|
||||||
foreach ($version['replace'] as $target => $constraint) {
|
|
||||||
$names[strtolower($target)] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$names = array_keys($names);
|
|
||||||
} else {
|
|
||||||
$names = array(strtolower($version['name']));
|
|
||||||
}
|
|
||||||
if (!$pool->isPackageAcceptable(strtolower($version['name']), VersionParser::parseStability($version['version']))) {
|
if (!$pool->isPackageAcceptable(strtolower($version['name']), VersionParser::parseStability($version['version']))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue