Skip to content

Commit

Permalink
Use Dictionary.subscript(_:default:) instead of coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
kaandedeoglu committed Jun 21, 2021
1 parent 6277183 commit bbcc724
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Shark/CountedSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ struct CountedSet<Element: Hashable>: Sequence {

@discardableResult
mutating func add(_ object: Element) -> Int {
let currentCount = backingDictionary[object] ?? 0
let currentCount = backingDictionary[object, default: 0]
let newCount = currentCount + 1
backingDictionary[object] = newCount
return newCount
}

func count(for object: Element) -> Int {
return backingDictionary[object] ?? 0
return backingDictionary[object, default: 0]
}

func makeIterator() -> Dictionary<Element, Int>.Values.Iterator {
Expand Down

0 comments on commit bbcc724

Please sign in to comment.