Skip to content

Commit 68e50d3

Browse files
committed
[stdlib] add debug-mode checks in _failEarlyRangeCheck
1 parent d777f20 commit 68e50d3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,16 @@ public struct Unsafe${Mutable}BufferPointer<Element>
165165

166166
@_inlineable
167167
public func _failEarlyRangeCheck(_ index: Int, bounds: Range<Int>) {
168-
// NOTE: This method is a no-op for performance reasons.
168+
// NOTE: In release mode, this method is a no-op for performance reasons.
169+
_debugPrecondition(index >= bounds.lowerBound)
170+
_debugPrecondition(index < bounds.upperBound)
169171
}
170172

171173
@_inlineable
172174
public func _failEarlyRangeCheck(_ range: Range<Int>, bounds: Range<Int>) {
173-
// NOTE: This method is a no-op for performance reasons.
175+
// NOTE: In release mode, this method is a no-op for performance reasons.
176+
_debugPrecondition(range.lowerBound >= bounds.lowerBound)
177+
_debugPrecondition(range.upperBound <= bounds.upperBound)
174178
}
175179

176180
public typealias Indices = CountableRange<Int>

0 commit comments

Comments
 (0)