Skip to content

Commit

Permalink
Use CompilingMatcher in DefaultPolicy for performance reasons (#11638)
Browse files Browse the repository at this point in the history
Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
  • Loading branch information
Toflar and Seldaek committed Sep 27, 2023
1 parent 755de04 commit f6ce834
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Composer/DependencyResolver/DefaultPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\Package\AliasPackage;
use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Semver\CompilingMatcher;
use Composer\Semver\Constraint\Constraint;

/**
Expand Down Expand Up @@ -49,10 +50,15 @@ public function versionCompare(PackageInterface $a, PackageInterface $b, string
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());
}

/**
Expand Down

0 comments on commit f6ce834

Please sign in to comment.