@@ -153,22 +153,23 @@ extension UnsafeRawBufferPointer.Iterator: IteratorProtocol, Sequence {
153
153
/// exists; otherwise, `nil`.
154
154
@inlinable
155
155
public mutating func next( ) -> UInt8 ? {
156
- if _position == _end { return nil }
157
-
156
+ guard let position = _position else {
157
+ return nil
158
+ }
158
159
// We can do an unchecked unwrap here by borrowing invariants from the pointer.
159
- // For a validly constructed buffer pointer, the only way _position can be nil is
160
- // if _end is also nil. We checked that case above. Thus, we can safely do an
161
- // unchecked unwrap here.
162
- //
163
- // Additionally, validly constructed buffer pointers also have an _end that is
164
- // strictly greater than or equal to _position, and so we do not need to do checked
165
- // arithmetic here as we cannot possibly overflow.
166
- //
160
+ // For a validly constructed buffer pointer, the only way _end can be nil is
161
+ // if _position is also nil. We checked that case above.
162
+ // Thus, we can safely do an unchecked unwrap here.
167
163
// We check these invariants in debug builds to defend against invalidly constructed
168
164
// pointers.
169
- _debugPrecondition ( _position! < _end!)
170
- let position = _position. _unsafelyUnwrappedUnchecked
165
+ _debugPrecondition ( _end != nil )
166
+ let end = _end. _unsafelyUnwrappedUnchecked
167
+ if position == end { return nil }
168
+ _debugPrecondition ( position < end)
171
169
let result = position. load ( as: UInt8 . self)
170
+ // Validly constructed buffer pointers also have an _end that is strictly
171
+ // greater than or equal to _position.
172
+ // So we do not need to do checked arithmetic here as we cannot possibly overflow.
172
173
_position = position + 1
173
174
return result
174
175
}
0 commit comments