From cfbe088b62535352889c3b02ef8740e57b0b8f44 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 13 Mar 2024 19:53:32 +0100 Subject: [PATCH 1/3] Micro: cache Groups --- src/Metadata/Api/Groups.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Metadata/Api/Groups.php b/src/Metadata/Api/Groups.php index 73341851a4b..1a2b23c4732 100644 --- a/src/Metadata/Api/Groups.php +++ b/src/Metadata/Api/Groups.php @@ -10,6 +10,7 @@ namespace PHPUnit\Metadata\Api; use function array_flip; +use function array_key_exists; use function array_unique; use function assert; use function strtolower; @@ -29,6 +30,11 @@ */ final class Groups { + /** + * @var array> + */ + private static array $groupCache = []; + /** * @psalm-param class-string $className * @psalm-param non-empty-string $methodName @@ -37,6 +43,12 @@ final class Groups */ public function groups(string $className, string $methodName, bool $includeVirtual = true): array { + $key = $className . '::' . $methodName . '::' . $includeVirtual; + + if (array_key_exists($key, self::$groupCache)) { + return self::$groupCache[$key]; + } + $groups = []; foreach (Registry::parser()->forClassAndMethod($className, $methodName)->isGroup() as $group) { @@ -50,7 +62,7 @@ public function groups(string $className, string $methodName, bool $includeVirtu } if (!$includeVirtual) { - return array_unique($groups); + return self::$groupCache[$key] = array_unique($groups); } foreach (Registry::parser()->forClassAndMethod($className, $methodName) as $metadata) { @@ -85,7 +97,7 @@ public function groups(string $className, string $methodName, bool $includeVirtu } } - return array_unique($groups); + return self::$groupCache[$key] = array_unique($groups); } /** From 522d1c537180e96f60061f0e006c9d29c619da52 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 13 Mar 2024 20:39:41 +0100 Subject: [PATCH 2/3] cleanup types --- .psalm/baseline.xml | 7 ------- src/Metadata/Api/Groups.php | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml index a1c98407ac5..a941c899ce9 100644 --- a/.psalm/baseline.xml +++ b/.psalm/baseline.xml @@ -640,13 +640,6 @@ - - - - - - ]]> - diff --git a/src/Metadata/Api/Groups.php b/src/Metadata/Api/Groups.php index 1a2b23c4732..6f304732761 100644 --- a/src/Metadata/Api/Groups.php +++ b/src/Metadata/Api/Groups.php @@ -31,7 +31,7 @@ final class Groups { /** - * @var array> + * @var array> */ private static array $groupCache = []; @@ -39,7 +39,7 @@ final class Groups * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * - * @psalm-return list + * @psalm-return array */ public function groups(string $className, string $methodName, bool $includeVirtual = true): array { From e6d645a26a78ff15b8cfb215cb117d3f0f5d11a0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 13 Mar 2024 20:41:28 +0100 Subject: [PATCH 3/3] more specific key-type --- src/Metadata/Api/Groups.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Metadata/Api/Groups.php b/src/Metadata/Api/Groups.php index 6f304732761..5c78cbdc340 100644 --- a/src/Metadata/Api/Groups.php +++ b/src/Metadata/Api/Groups.php @@ -31,7 +31,7 @@ final class Groups { /** - * @var array> + * @var array> */ private static array $groupCache = []; @@ -39,7 +39,7 @@ final class Groups * @psalm-param class-string $className * @psalm-param non-empty-string $methodName * - * @psalm-return array + * @psalm-return array */ public function groups(string $className, string $methodName, bool $includeVirtual = true): array {