Stop closure efficiency.
This commit is contained in:
parent
df32a51395
commit
2857b1cd55
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user