[swift-evolution] Improvement proposal: change overflow behavior in successor()/predecessor() methods for Int types

Vladimir.S svabox at gmail.com
Thu Apr 7 13:27:41 CDT 2016


OK, thank you for the clarification Dmitri.
If these methods are going away - no possible problems :-)
Will we have some kind of .next() method for integers in new indexing model 
and in Swift 3.0 in general?


(But actually I don't agree that there is all OK with these functions in 
current version of Swift. "Not designed" - understand, but they can be 
used(so they will! be used) "out of the box", even Int8 has these methods,
Int32.max is just 2GB for [Int8] etc..
Yes, in case of using successor() only with Int64 only for indices of Array 
- all looks like OK.)


On 07.04.2016 20:54, Dmitri Gribenko wrote:
> This was done for performance reasons.  Array's indices are Ints, and
> adding an overflow check here was causing significant performance
> issues when iterating over arrays.  These methods were not designed to
> be used in contexts other than indices.  When ints are used as
> indices, doing an overflow check in successor() does not prevent any
> mistakes, since Array's bounds are always tighter than
> Int.min...Int.max.
>
> These methods are going away in the new indexing model.
> https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160229/011552.html
>
> Dmitri


More information about the swift-evolution mailing list