perf: cache is_dir lookups in TestRepository::make() (#2027)

Co-authored-by: Sylvain Valienne <2300259+sylouuu@users.noreply.github.com>
Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
Syl
2026-11-14 21:07:40 +01:00
committed by GitHub
parent 38c79452c1
commit 61adbcfd34
+8 -1
View File
@@ -31,6 +31,11 @@ final class TestRepository
*/
private array $uses = [];
/**
* @var array<string, bool>
*/
private array $isDirectory = [];
/**
* @var array<int, TestCaseFilter>
*/
@@ -156,7 +161,9 @@ final class TestRepository
foreach ($this->uses as $path => $uses) {
[$classOrTraits, $groups, $hooks] = $uses;
if ((! is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) {
$isDirectory = $this->isDirectory[$path] ??= is_dir($path);
if ((! $isDirectory && $testCase->filename === $path) || ($isDirectory && $startsWith($testCase->filename, $path))) {
foreach ($classOrTraits as $class) {
/** @var string $class */
if (class_exists($class)) {