Skip to content

Commit f9e5e7a

Browse files
committed
refactor(model): Use a list instead of a set for creating nodes
There should be no need for the implicit de-duplication via a set here. Using a list (as the function documentation actually already says) avoids the need for the final `toList()` conversion (which duplicates nodes in memory) and avoids the performance penalty on insertion for sets. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 3c2cfe8 commit f9e5e7a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

model/src/main/kotlin/utils/DependencyGraphBuilder.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,13 @@ class DependencyGraphBuilder<D>(
439439
}
440440

441441
/**
442-
* Convert the direct dependency references of all projects to a list of nodes and edges that represent the final
443-
* dependency graph. Apply the given [indexMapping] to the indices pointing to dependencies.
442+
* Convert the direct dependency references of all projects to a list of nodes and a set of edges that represent the
443+
* final dependency graph. Apply the given [indexMapping] to the indices pointing to dependencies.
444444
*/
445445
private fun Collection<DependencyReference>.toGraph(
446446
indexMapping: IntArray
447447
): Pair<List<DependencyGraphNode>, Set<DependencyGraphEdge>> {
448-
val nodes = mutableSetOf<DependencyGraphNode>()
448+
val nodes = mutableListOf<DependencyGraphNode>()
449449
val edges = mutableSetOf<DependencyGraphEdge>()
450450
val nodeIndices = mutableMapOf<NodeKey, Int>()
451451

@@ -464,7 +464,7 @@ private fun Collection<DependencyReference>.toGraph(
464464
}
465465
}
466466

467-
return nodes.toList() to edges
467+
return nodes to edges
468468
}
469469

470470
private fun Collection<DependencyReference>.visitEach(visit: (ref: DependencyReference) -> Unit) {

0 commit comments

Comments
 (0)