Skip to content

Commit 99a80f3

Browse files
Copilotthorsten
andcommitted
Optimize cycle detection with isset() for O(1) lookup performance
Co-authored-by: thorsten <45284+thorsten@users.noreply.github.com>
1 parent 4d9c3af commit 99a80f3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

phpmyfaq/src/phpMyFAQ/Category/Order.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ public function getCategoryTree(array $categories, int $parentId = 0, array &$vi
138138

139139
if ($categoryParentId === $parentId) {
140140
// Check if this category has already been visited to prevent cycles
141-
if (in_array($categoryId, $visited, true)) {
141+
if (isset($visited[$categoryId])) {
142142
continue;
143143
}
144144

145145
// Add current category to visited list
146-
$visited[] = $categoryId;
146+
$visited[$categoryId] = true;
147147

148148
$childCategories = $this->getCategoryTree($categories, $categoryId, $visited);
149149
$result[$categoryId] = $childCategories;

0 commit comments

Comments
 (0)