Rewrite the Bag.count implementation

This implementation is both short and fast in compilation times.
This commit is contained in:
Sidharth Juyal 2016-06-02 11:30:56 +02:00
parent 00e0f5e689
commit ae9c8e3fd9
1 changed files with 1 additions and 4 deletions

View File

@ -152,10 +152,7 @@ public struct Bag<T> : CustomDebugStringConvertible {
- returns: Number of elements in bag.
*/
public var count: Int {
var dictionaryCount = 0
if let dc = _dictionary?.count {
dictionaryCount = dc
}
let dictionaryCount: Int = _dictionary?.count ?? 0
return _pairs.count + (_value0 != nil ? 1 : 0) + (_value1 != nil ? 1 : 0) + dictionaryCount
}