From 0221eda956814823ef7fb207c8ab8576060a3705 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 16 Dec 2017 11:15:36 -0800 Subject: [PATCH] =?UTF-8?q?Add=20Node.existingOrNewChildNode=20=E2=80=94?= =?UTF-8?q?=20recycles=20an=20existing=20node.=20Creates=20a=20new=20node?= =?UTF-8?q?=20only=20when=20needed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/RSTree/RSTree/Node.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Frameworks/RSTree/RSTree/Node.swift b/Frameworks/RSTree/RSTree/Node.swift index bf2270253..d0053f6ce 100644 --- a/Frameworks/RSTree/RSTree/Node.swift +++ b/Frameworks/RSTree/RSTree/Node.swift @@ -81,6 +81,14 @@ public final class Node: Hashable { return node } + public func existingOrNewChildNode(with representedObject: AnyObject) -> Node { + + if let node = childNodeRepresentingObject(representedObject) { + return node + } + return createChildNode(representedObject) + } + public func createChildNode(_ representedObject: AnyObject) -> Node { // Just creates — doesn’t add it.