Skip to content

Commit 577f028

Browse files
authored
[gardening]: merge two dictionary accesses into one (#326)
micro-optimization to merge two dictionary accesses into one
1 parent e9f82d1 commit 577f028

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Workflow/Sources/SubtreeManager.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ extension WorkflowNode.SubtreeManager {
192192
/// A unique key used to identify this child workflow
193193
let childKey = ChildKey(childType: Child.self, key: key)
194194

195-
/// If the key already exists in `used`, then a workflow of the same type has been rendered multiple times
196-
/// during this render pass with the same key. This is not allowed.
197-
guard usedChildWorkflows[childKey] == nil else {
198-
fatalError("Child workflows of the same type must be given unique keys. Duplicate workflows of type \(Child.self) were encountered with the key \"\(key)\" in \(WorkflowType.self)")
199-
}
200-
201195
let child: ChildWorkflow<Child>
202196
let eventPipe = EventPipe()
203197
eventPipes.append(eventPipe)
@@ -232,7 +226,12 @@ extension WorkflowNode.SubtreeManager {
232226

233227
/// Store the resolved child in `used`. This allows us to a) hold on to any used children after this render
234228
/// pass, and b) ensure that we never allow the use of a given workflow type with identical keys.
235-
usedChildWorkflows[childKey] = child
229+
let keyWasUnused = usedChildWorkflows.updateValue(child, forKey: childKey) == nil
230+
231+
/// If the key was already in `used`, then a workflow of the same type was rendered multiple times
232+
/// during this render pass with the same key. This is not allowed.
233+
precondition(keyWasUnused, "Child workflows of the same type must be given unique keys. Duplicate workflows of type \(Child.self) were encountered with the key \"\(key)\" in \(WorkflowType.self)")
234+
236235
return child.render()
237236
}
238237

0 commit comments

Comments
 (0)