From 878e34e83f9d57d309f8881cec788773d1e2b2f3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 7 Sep 2019 15:38:59 +0200 Subject: [PATCH] Optimised tight cycle in `PHPUnit\Util\Test#parseTestMethodAnnotations()` This method is used very often (10k+ times in a small test suite), so it needs to be quite efficient, if possible. --- src/Util/Test.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Util/Test.php b/src/Util/Test.php index f9e95e6b706..15ec9a1e324 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -306,14 +306,14 @@ public static function getProvidedData(string $className, string $methodName): ? public static function parseTestMethodAnnotations(string $className, ?string $methodName = ''): array { + $registry = Registry::singleton(); + if ($methodName !== null) { try { return [ - 'class' => Registry::singleton() - ->forClassName($className) + 'method' => $registry->forMethod($className, $methodName) ->symbolAnnotations(), - 'method' => Registry::singleton() - ->forMethod($className, $methodName) + 'class' => $registry->forClassName($className) ->symbolAnnotations(), ]; } catch (Exception $methodNotFound) { @@ -322,10 +322,9 @@ public static function parseTestMethodAnnotations(string $className, ?string $me } return [ - 'class' => Registry::singleton() - ->forClassName($className) - ->symbolAnnotations(), 'method' => null, + 'class' => $registry->forClassName($className) + ->symbolAnnotations(), ]; }