Stop closure efficiency.

This commit is contained in:
Hedden, Kyle Matthew 2023-12-18 17:22:40 -05:00
parent df32a51395
commit 2857b1cd55

View File

@ -69,11 +69,12 @@ public extension Array where Element == MoleculeModelProtocol {
func depthFirstTraverse(options: TreeTraversalOptions, depth: Int, onVisit: (Int, MoleculeModelProtocol, inout Bool) -> Void) {
var shouldStop = false
let stopIntercept = { depth, molecule, stop in
onVisit(depth, molecule, &shouldStop)
stop = shouldStop
}
for molecule in self {
molecule.depthFirstTraverse(options: options, depth: depth) { depth, molecule, stop in
onVisit(depth, molecule, &shouldStop)
stop = shouldStop
}
molecule.depthFirstTraverse(options: options, depth: depth, onVisit: stopIntercept)
if shouldStop { break }
}
}