Skip to content

[gardening]: merge two dictionary accesses into one #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Workflow/Sources/SubtreeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ extension WorkflowNode.SubtreeManager {
/// A unique key used to identify this child workflow
let childKey = ChildKey(childType: Child.self, key: key)

/// If the key already exists in `used`, then a workflow of the same type has been rendered multiple times
/// during this render pass with the same key. This is not allowed.
guard usedChildWorkflows[childKey] == nil else {
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)")
}

let child: ChildWorkflow<Child>
let eventPipe = EventPipe()
eventPipes.append(eventPipe)
Expand Down Expand Up @@ -232,7 +226,12 @@ extension WorkflowNode.SubtreeManager {

/// Store the resolved child in `used`. This allows us to a) hold on to any used children after this render
/// pass, and b) ensure that we never allow the use of a given workflow type with identical keys.
usedChildWorkflows[childKey] = child
let keyWasUnused = usedChildWorkflows.updateValue(child, forKey: childKey) == nil

/// If the key was already in `used`, then a workflow of the same type was rendered multiple times
/// during this render pass with the same key. This is not allowed.
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)")

return child.render()
}

Expand Down
Loading