1
0
Fork 0

Use CompilingMatcher in DefaultPolicy for performance reasons (#11638)

Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
pull/11664/head
Yanick Witschi 2023-09-27 09:08:29 +02:00 committed by GitHub
parent 755de04bf5
commit f6ce8349c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -15,6 +15,7 @@ namespace Composer\DependencyResolver;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Semver\CompilingMatcher;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
/** /**
@ -49,12 +50,17 @@ class DefaultPolicy implements PolicyInterface
return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB]; return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB];
} }
// dev versions need to be compared as branches via matchSpecific's special treatment, the rest can be optimized with compiling matcher
if (strpos($a->getVersion(), 'dev-') === 0 || strpos($b->getVersion(), 'dev-') === 0) {
$constraint = new Constraint($operator, $b->getVersion()); $constraint = new Constraint($operator, $b->getVersion());
$version = new Constraint('==', $a->getVersion()); $version = new Constraint('==', $a->getVersion());
return $constraint->matchSpecific($version, true); return $constraint->matchSpecific($version, true);
} }
return CompilingMatcher::match(new Constraint($operator, $b->getVersion()), Constraint::OP_EQ, $a->getVersion());
}
/** /**
* @param int[] $literals * @param int[] $literals
* @param string $requiredPackage * @param string $requiredPackage