Skip to content

Commit e0137c9

Browse files
committed
Refactoring
1 parent 61579ef commit e0137c9

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

Sources/Atoms/Core/StoreContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ private extension StoreContext {
418418
performUpdate(subscription: edge.to, dependency: dependencyCache.atom)
419419
}
420420

421-
// Notify the observer of the update after all updates are complete.
421+
// Notify the observers after all updates are complete.
422422
notifyUpdateToObservers()
423423
}
424424

Sources/Atoms/Core/TopologicalSorting.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ private struct TopologicalSorting {
2424
private let store: AtomStore
2525
private(set) var edges = ContiguousArray<Edge<AtomKey>>()
2626
private(set) var subscriptionEdges = ContiguousArray<Edge<Subscription>>()
27-
private var trace = Set<Vertex>()
27+
private var atomTrace = Set<AtomKey>()
28+
private var subscriberTrace = Set<SubscriberKey>()
2829

2930
init(key: AtomKey, store: AtomStore) {
3031
self.key = key
@@ -37,15 +38,10 @@ private struct TopologicalSorting {
3738
}
3839

3940
private extension TopologicalSorting {
40-
enum Vertex: Hashable {
41-
case atom(key: AtomKey)
42-
case subscriber(key: SubscriberKey)
43-
}
44-
4541
mutating func traverse(key: AtomKey) {
4642
if let children = store.graph.children[key] {
4743
for child in ContiguousArray(children) {
48-
guard !trace.contains(.atom(key: child)) else {
44+
guard !atomTrace.contains(child) else {
4945
continue
5046
}
5147

@@ -55,21 +51,21 @@ private extension TopologicalSorting {
5551

5652
if let subscriptions = store.state.subscriptions[key] {
5753
for (subscriberKey, subscription) in ContiguousArray(subscriptions) {
58-
guard !trace.contains(.subscriber(key: subscriberKey)) else {
54+
guard !subscriberTrace.contains(subscriberKey) else {
5955
continue
6056
}
6157

6258
let edge = Edge(from: key, to: subscription)
6359
subscriptionEdges.append(edge)
64-
trace.insert(.subscriber(key: subscriberKey))
60+
subscriberTrace.insert(subscriberKey)
6561
}
6662
}
6763
}
6864

6965
mutating func traverse(key: AtomKey, from fromKey: AtomKey) {
7066
let edge = Edge(from: fromKey, to: key)
7167

72-
trace.insert(.atom(key: key))
68+
atomTrace.insert(key)
7369
traverse(key: key)
7470
edges.append(edge)
7571
}

0 commit comments

Comments
 (0)