Skip to content

Commit

Permalink
Bag.insert: explicitly checking for overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Nov 29, 2015
1 parent 891b0e0 commit 92e4ac8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ReactiveCocoa/Swift/Bag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public struct Bag<Element> {
/// Inserts the given value in the collection, and returns a token that can
/// later be passed to removeValueForToken().
public mutating func insert(value: Element) -> RemovalToken {
let nextIdentifier = currentIdentifier &+ 1
if nextIdentifier == 0 {
let (nextIdentifier, overflow) = UInt.addWithOverflow(currentIdentifier, 1)
if overflow {
reindex()
}

let token = RemovalToken(identifier: currentIdentifier)
let element = BagElement(value: value, identifier: currentIdentifier, token: token)

elements.append(element)
currentIdentifier++
currentIdentifier = nextIdentifier

return token
}
Expand Down

0 comments on commit 92e4ac8

Please sign in to comment.