From b98893f7d8b7ae95955eb7d26921b81818456ce7 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 27 Oct 2024 19:59:15 +0100 Subject: optimize project find --- index.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 463af36..a5342f8 100644 --- a/index.php +++ b/index.php @@ -2,10 +2,11 @@ function find_projects(string $path, array $projects = []): array { $directories = glob($path . "/{.[!.],}*", GLOB_ONLYDIR | GLOB_BRACE); - foreach ($directories as $directory) { - if (str_ends_with($directory, ".git")) { - $projects[] = substr($directory, 0, -4); - } else { + if (($idx = array_search("$path/.git", $directories)) !== false) { + $projects[] = substr($directories[$idx], 0, -4); + } + else { + foreach ($directories as $directory) { $projects += find_projects($directory, $projects); } } -- cgit v1.2.3