From f6ce8349c511f6ce991b9cff763c16f8c3f1e070 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Wed, 27 Sep 2023 09:08:29 +0200 Subject: [PATCH] Use CompilingMatcher in DefaultPolicy for performance reasons (#11638) Co-authored-by: Jordi Boggiano --- src/Composer/DependencyResolver/DefaultPolicy.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Composer/DependencyResolver/DefaultPolicy.php b/src/Composer/DependencyResolver/DefaultPolicy.php index 52cbff350..8d27a6602 100644 --- a/src/Composer/DependencyResolver/DefaultPolicy.php +++ b/src/Composer/DependencyResolver/DefaultPolicy.php @@ -15,6 +15,7 @@ namespace Composer\DependencyResolver; use Composer\Package\AliasPackage; use Composer\Package\BasePackage; use Composer\Package\PackageInterface; +use Composer\Semver\CompilingMatcher; use Composer\Semver\Constraint\Constraint; /** @@ -49,10 +50,15 @@ class DefaultPolicy implements PolicyInterface return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB]; } - $constraint = new Constraint($operator, $b->getVersion()); - $version = new Constraint('==', $a->getVersion()); + // 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()); + $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()); } /**