Skip to content

Commit 31234f6

Browse files
committed
stdlib: rewrite optional-check to improve performance
The statement "if x == nil { }" involves creating an Optional.none for the RHS and calling the == function.
1 parent 4b5e617 commit 31234f6

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,10 @@ public struct Unsafe${Mutable}BufferPointer<Element>
126126

127127
/// The number of elements in the buffer.
128128
public var count: Int {
129-
if _position == nil {
130-
_sanityCheck(_end == nil)
131-
return 0
129+
if let pos = _position {
130+
return _end! - pos
132131
}
133-
return _end! - _position!
132+
return 0
134133
}
135134

136135
let _position, _end: Unsafe${Mutable}Pointer<Element>?

0 commit comments

Comments
 (0)