From 2857b1cd559d13f63814b68688cc451e6abbe212 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Mon, 18 Dec 2023 17:22:40 -0500 Subject: [PATCH] Stop closure efficiency. --- .../Protocols/ModelProtocols/MoleculeModelProtocol.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift b/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift index 0fcab2d0..e56840e8 100644 --- a/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/ModelProtocols/MoleculeModelProtocol.swift @@ -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 } } }