File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ public struct StrideThroughIterator<Element : Strideable> : IteratorProtocol {
227
227
internal let _end: Element
228
228
internal let _stride: Element.Stride
229
229
internal var _current: (index: Int?, value: Element)
230
- internal var _done : Bool = false
230
+ internal var _didReturnEnd : Bool = false
231
231
232
232
internal init(_start: Element, end: Element, stride: Element.Stride) {
233
233
self._start = _start
@@ -241,13 +241,13 @@ public struct StrideThroughIterator<Element : Strideable> : IteratorProtocol {
241
241
///
242
242
/// Once `nil` has been returned, all subsequent calls return `nil`.
243
243
public mutating func next() -> Element? {
244
- if _done {
245
- return nil
246
- }
247
244
let result = _current.value
248
245
if _stride > 0 ? result >= _end : result <= _end {
249
- if result == _end {
250
- _done = true
246
+ // This check is needed because if we just changed the above operators
247
+ // to > and <, respectively, we might advance current past the end
248
+ // and throw it out of bounds (e.g. above Int.max) unnecessarily.
249
+ if result == _end && !_didReturnEnd {
250
+ _didReturnEnd = true
251
251
return result
252
252
}
253
253
return nil
You can’t perform that action at this time.
0 commit comments