From 35cb0fe0789e4bb78683fb6ee99a0aa6deffb96b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 2 Dec 2017 16:12:09 -0800 Subject: [PATCH] Get rid of the lock. Add comment that Node is main-thread-only; add precondition to init method. Fix #230. --- Frameworks/RSTree/RSTree/Node.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Frameworks/RSTree/RSTree/Node.swift b/Frameworks/RSTree/RSTree/Node.swift index 618bad9d4..bf2270253 100644 --- a/Frameworks/RSTree/RSTree/Node.swift +++ b/Frameworks/RSTree/RSTree/Node.swift @@ -8,6 +8,8 @@ import Foundation +// Main thread only. + public final class Node: Hashable { public weak var parent: Node? @@ -17,7 +19,6 @@ public final class Node: Hashable { public var childNodes: [Node]? public let hashValue: Int private static var incrementingID = 0 - private static var incrementingIDLock = NSLock() public var isRoot: Bool { get { @@ -63,14 +64,14 @@ public final class Node: Hashable { } public init(representedObject: AnyObject, parent: Node?) { - + + precondition(Thread.isMainThread) + self.representedObject = representedObject self.parent = parent - Node.incrementingIDLock.lock() self.hashValue = Node.incrementingID Node.incrementingID += 1 - Node.incrementingIDLock.unlock() } public class func genericRootNode() -> Node {