Skip to content

Commit 79bd1f8

Browse files
committed
Updated Rector to commit cdd219c5341e7ef841c1567960e60a945e9b59f2
rectorphp/rector-src@cdd219c perf: use hash map for installed packages (#7878)
1 parent 8049f60 commit 79bd1f8

4 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '52c6ece13308d46109bd1c2f4927592244d1c7b0';
22+
public const PACKAGE_VERSION = 'cdd219c5341e7ef841c1567960e60a945e9b59f2';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-04-07 18:39:52';
27+
public const RELEASE_DATE = '2026-04-07 18:40:28';
2828
/**
2929
* @var int
3030
*/

src/Composer/InstalledPackageResolver.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class InstalledPackageResolver
1919
*/
2020
private ?string $projectDirectory = null;
2121
/**
22-
* @var null|InstalledPackage[]
22+
* @var null|array<string, InstalledPackage>
2323
*/
2424
private ?array $resolvedInstalledPackages = null;
2525
public function __construct(?string $projectDirectory = null)
@@ -32,7 +32,7 @@ public function __construct(?string $projectDirectory = null)
3232
Assert::directory($projectDirectory);
3333
}
3434
/**
35-
* @return InstalledPackage[]
35+
* @return array<string, InstalledPackage>
3636
*/
3737
public function resolve(): array
3838
{
@@ -52,24 +52,22 @@ public function resolve(): array
5252
}
5353
public function resolvePackageVersion(string $packageName): ?string
5454
{
55-
$installedPackages = $this->resolve();
56-
foreach ($installedPackages as $installedPackage) {
57-
if ($installedPackage->getName() !== $packageName) {
58-
continue;
59-
}
60-
return $installedPackage->getVersion();
55+
$package = $this->resolve()[$packageName] ?? null;
56+
if (!$package instanceof InstalledPackage) {
57+
return null;
6158
}
62-
return null;
59+
return $package->getVersion();
6360
}
6461
/**
6562
* @param mixed[] $packages
66-
* @return InstalledPackage[]
63+
* @return array<string, InstalledPackage>
6764
*/
6865
private function createInstalledPackages(array $packages): array
6966
{
7067
$installedPackages = [];
7168
foreach ($packages as $package) {
72-
$installedPackages[] = new InstalledPackage($package['name'], $package['version_normalized']);
69+
$name = $package['name'];
70+
$installedPackages[$name] = new InstalledPackage($name, $package['version_normalized']);
7371
}
7472
return $installedPackages;
7573
}

src/Composer/ValueObject/InstalledPackage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
declare (strict_types=1);
44
namespace Rector\Composer\ValueObject;
55

6+
/**
7+
* @api
8+
*/
69
final class InstalledPackage
710
{
811
/**

src/Set/ValueObject/ComposerTriggeredSet.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,15 @@ public function getSetFilePath(): string
5151
return $this->setFilePath;
5252
}
5353
/**
54-
* @param InstalledPackage[] $installedPackages
54+
* @param array<string, InstalledPackage> $installedPackages
5555
*/
5656
public function matchInstalledPackages(array $installedPackages): bool
5757
{
58-
foreach ($installedPackages as $installedPackage) {
59-
if ($installedPackage->getName() !== $this->packageName) {
60-
continue;
61-
}
62-
return Semver::satisfies($installedPackage->getVersion(), '^' . $this->version);
58+
$package = $installedPackages[$this->packageName] ?? null;
59+
if (!$package instanceof InstalledPackage) {
60+
return \false;
6361
}
64-
return \false;
62+
return Semver::satisfies($package->getVersion(), '^' . $this->version);
6563
}
6664
public function getName(): string
6765
{

0 commit comments

Comments
 (0)