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) {
|
func depthFirstTraverse(options: TreeTraversalOptions, depth: Int, onVisit: (Int, MoleculeModelProtocol, inout Bool) -> Void) {
|
||||||
var shouldStop = false
|
var shouldStop = false
|
||||||
|
let stopIntercept = { depth, molecule, stop in
|
||||||
|
onVisit(depth, molecule, &shouldStop)
|
||||||
|
stop = shouldStop
|
||||||
|
}
|
||||||
for molecule in self {
|
for molecule in self {
|
||||||
molecule.depthFirstTraverse(options: options, depth: depth) { depth, molecule, stop in
|
molecule.depthFirstTraverse(options: options, depth: depth, onVisit: stopIntercept)
|
||||||
onVisit(depth, molecule, &shouldStop)
|
|
||||||
stop = shouldStop
|
|
||||||
}
|
|
||||||
if shouldStop { break }
|
if shouldStop { break }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user