1
0
Fork 0

Improved hasPackage() performance

pull/8438/head
Michael Thessel 2019-11-20 14:58:28 -08:00
parent 6ffd3eb67c
commit f8010d5220
1 changed files with 5 additions and 6 deletions

View File

@ -28,6 +28,7 @@ class ArrayRepository extends BaseRepository
{ {
/** @var PackageInterface[] */ /** @var PackageInterface[] */
protected $packages; protected $packages;
protected $packageMap;
public function __construct(array $packages = array()) public function __construct(array $packages = array())
{ {
@ -121,15 +122,13 @@ class ArrayRepository extends BaseRepository
*/ */
public function hasPackage(PackageInterface $package) public function hasPackage(PackageInterface $package)
{ {
$packageId = $package->getUniqueName(); if (empty($this->packageMap)) {
foreach ($this->getPackages() as $repoPackage) { foreach ($this->getPackages() as $repoPackage) {
if ($packageId === $repoPackage->getUniqueName()) { $this->packageMap[$repoPackage->getUniqueName()] = $repoPackage;
return true;
} }
} }
return false; return isset($this->packageMap[$package->getUniqueName()]);
} }
/** /**