Skip to content

Commit 379f6f6

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 a39f3f0 commit 379f6f6

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

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)