Skip to content

Commit

Permalink
[Observation] Optimize cancellation path to avoid excessive copies
Browse files Browse the repository at this point in the history
  • Loading branch information
phausler committed Apr 26, 2024
1 parent 9773e89 commit a8334ea
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,10 @@ public struct ObservationRegistrar: Sendable {
internal mutating func cancel(_ id: Int) {
if let observation = observations.removeValue(forKey: id) {
for keyPath in observation.properties {
if var ids = lookups[keyPath] {
ids.remove(id)
if ids.count == 0 {
lookups.removeValue(forKey: keyPath)
} else {
lookups[keyPath] = ids
if let index = lookups.index(forKey: keyPath) {
lookups.values[index].remove(id)
if lookups.values[index].isEmpty {
lookups.remove(at: index)
}
}
}
Expand Down

0 comments on commit a8334ea

Please sign in to comment.