Improved hasPackage() performance
parent
6ffd3eb67c
commit
f8010d5220
|
@ -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()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue