Skip to content

Commit

Permalink
chore(model): Return early from collectDependencies()
Browse files Browse the repository at this point in the history
Reduce nesting by returning early for an invalid `maxDepth`.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Dec 16, 2024
1 parent 81f58ea commit 15a6021
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions model/src/main/kotlin/DependencyGraphNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,15 @@ private fun collectDependencies(
ids: MutableSet<Identifier>,
visited: MutableSet<DependencyGraphNode> = mutableSetOf()
) {
if (maxDepth != 0) {
nodes.forEach { node ->
val cursor = node as DependencyRefCursor
if (cursor.current !in visited) {
visited += cursor.current
if (matcher(node)) ids += node.id

node.visitDependencies { collectDependencies(it, maxDepth - 1, matcher, ids, visited) }
}
if (maxDepth == 0) return

nodes.forEach { node ->
val cursor = node as DependencyRefCursor
if (cursor.current !in visited) {
visited += cursor.current
if (matcher(node)) ids += node.id

node.visitDependencies { collectDependencies(it, maxDepth - 1, matcher, ids, visited) }
}
}
}

0 comments on commit 15a6021

Please sign in to comment.