Skip to content

Commit fa79e93

Browse files
committed
fix(model-sync-lib): optimized deletion order
1 parent 1a1abde commit fa79e93

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

model-sync-lib/src/main/kotlin/org/modelix/model/sync/ModelImporter.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ModelImporter(private val root: INode, val stats: ImportStats? = null) {
3636
val originalIdToRef: MutableMap<String, INodeReference> = buildRefIndex(allNodes)
3737
syncAllReferences(allNodes, originalIdToSpec, originalIdToRef)
3838

39-
deleteAllExtraChildren(allNodes, originalIdToSpec)
39+
deleteAllExtraChildren(root, originalIdToSpec)
4040
}
4141

4242
private fun buildExistingIndex(allNodes: List<INode>): MutableMap<String, INode> {
@@ -250,18 +250,19 @@ class ModelImporter(private val root: INode, val stats: ImportStats? = null) {
250250

251251
}
252252

253-
private fun deleteAllExtraChildren(allNodes: List<INode>, originalIdToSpec: MutableMap<String, NodeData>) {
253+
private fun deleteAllExtraChildren(root: INode, originalIdToSpec: MutableMap<String, NodeData>) {
254254
val toBeRemoved = mutableListOf<INode>()
255-
allNodes.forEach { node ->
256-
node.allChildren.forEach {
257-
if (!originalIdToSpec.containsKey(it.originalId())) {
258-
toBeRemoved.add(it)
259-
}
255+
root.allChildren.forEach {
256+
if (!originalIdToSpec.containsKey(it.originalId())) {
257+
toBeRemoved.add(it)
260258
}
261259
}
262-
toBeRemoved.asReversed().forEach {// delete bottom-up
260+
toBeRemoved.forEach {
263261
it.parent?.removeChildWithStats(it)
264262
}
263+
root.allChildren.forEach {
264+
deleteAllExtraChildren(it, originalIdToSpec)
265+
}
265266
}
266267

267268
private fun NodeData.getIndexWithinRole(parent: NodeData) : Int =

0 commit comments

Comments
 (0)