@@ -112,8 +112,8 @@ public struct Unsafe${Mutable}RawBufferPointer {
112
112
public init (
113
113
@_nonEphemeral start: Unsafe ${ Mutable} RawPointer? , count: Int
114
114
) {
115
- _debugPrecondition ( count >= 0 , " ${Self} with negative count " )
116
- _debugPrecondition ( count == 0 || start != nil ,
115
+ _boundsCheckPrecondition ( count >= 0 , " ${Self} with negative count " )
116
+ _boundsCheckPrecondition ( count == 0 || start != nil ,
117
117
" ${Self} has a nil start and nonzero count " )
118
118
_position = start
119
119
_end = start. map { $0 + _assumeNonNegative( count) }
@@ -159,7 +159,7 @@ extension UnsafeRawBufferPointer.Iterator: IteratorProtocol, Sequence {
159
159
//
160
160
// We check these invariants in debug builds to defend against invalidly constructed
161
161
// pointers.
162
- _debugPrecondition ( _position! < _end!)
162
+ _boundsCheckPrecondition ( _position! < _end!)
163
163
let position = _position. _unsafelyUnwrappedUnchecked
164
164
let result = position. load ( as: UInt8 . self)
165
165
_position = position + 1
@@ -239,14 +239,14 @@ extension Unsafe${Mutable}RawBufferPointer: ${Mutable}Collection {
239
239
@inlinable
240
240
public subscript( i: Int) - > Element {
241
241
get {
242
- _debugPrecondition ( i >= 0 )
243
- _debugPrecondition ( i < endIndex)
242
+ _boundsCheckPrecondition ( i >= 0 )
243
+ _boundsCheckPrecondition ( i < endIndex)
244
244
return _position. _unsafelyUnwrappedUnchecked. load ( fromByteOffset: i, as: UInt8 . self)
245
245
}
246
246
% if mutable:
247
247
nonmutating set {
248
- _debugPrecondition ( i >= 0 )
249
- _debugPrecondition ( i < endIndex)
248
+ _boundsCheckPrecondition ( i >= 0 )
249
+ _boundsCheckPrecondition ( i < endIndex)
250
250
_position. _unsafelyUnwrappedUnchecked. storeBytes ( of: newValue, toByteOffset: i, as: UInt8 . self)
251
251
}
252
252
% end # mutable
@@ -259,15 +259,15 @@ extension Unsafe${Mutable}RawBufferPointer: ${Mutable}Collection {
259
259
@inlinable
260
260
public subscript( bounds: Range < Int > ) -> SubSequence {
261
261
get {
262
- _debugPrecondition ( bounds. lowerBound >= startIndex)
263
- _debugPrecondition ( bounds. upperBound <= endIndex)
262
+ _boundsCheckPrecondition ( bounds. lowerBound >= startIndex)
263
+ _boundsCheckPrecondition ( bounds. upperBound <= endIndex)
264
264
return Slice ( base: self , bounds: bounds)
265
265
}
266
266
% if mutable:
267
267
nonmutating set {
268
- _debugPrecondition ( bounds. lowerBound >= startIndex)
269
- _debugPrecondition ( bounds. upperBound <= endIndex)
270
- _debugPrecondition ( bounds. count == newValue. count)
268
+ _boundsCheckPrecondition ( bounds. lowerBound >= startIndex)
269
+ _boundsCheckPrecondition ( bounds. upperBound <= endIndex)
270
+ _boundsCheckPrecondition ( bounds. count == newValue. count)
271
271
272
272
if !newValue. isEmpty {
273
273
( baseAddress! + bounds. lowerBound) . copyMemory (
@@ -292,8 +292,8 @@ extension Unsafe${Mutable}RawBufferPointer: ${Mutable}Collection {
292
292
@inlinable
293
293
public func swapAt( _ i: Int , _ j: Int ) {
294
294
guard i != j else { return }
295
- _debugPrecondition ( i >= 0 && j >= 0 )
296
- _debugPrecondition ( i < endIndex && j < endIndex)
295
+ _boundsCheckPrecondition ( i >= 0 && j >= 0 )
296
+ _boundsCheckPrecondition ( i < endIndex && j < endIndex)
297
297
let pi = ( _position! + i)
298
298
let pj = ( _position! + j)
299
299
let tmp = pi. load ( fromByteOffset: 0 , as: UInt8 . self)
@@ -394,8 +394,8 @@ extension Unsafe${Mutable}RawBufferPointer {
394
394
/// memory.
395
395
@inlinable
396
396
public func load< T> ( fromByteOffset offset: Int = 0 , as type: T . Type ) -> T {
397
- _debugPrecondition ( offset >= 0 , " ${Self}.load with negative offset " )
398
- _debugPrecondition ( offset + MemoryLayout < T > . size <= self . count,
397
+ _boundsCheckPrecondition ( offset >= 0 , " ${Self}.load with negative offset " )
398
+ _boundsCheckPrecondition ( offset + MemoryLayout < T > . size <= self . count,
399
399
" ${Self}.load out of bounds " )
400
400
return baseAddress!. load ( fromByteOffset: offset, as: T . self)
401
401
}
@@ -436,8 +436,8 @@ extension Unsafe${Mutable}RawBufferPointer {
436
436
fromByteOffset offset: Int = 0 ,
437
437
as type: T . Type
438
438
) -> T {
439
- _debugPrecondition ( offset >= 0 , " ${Self}.load with negative offset " )
440
- _debugPrecondition ( offset + MemoryLayout < T > . size <= self . count,
439
+ _boundsCheckPrecondition ( offset >= 0 , " ${Self}.load with negative offset " )
440
+ _boundsCheckPrecondition ( offset + MemoryLayout < T > . size <= self . count,
441
441
" ${Self}.load out of bounds " )
442
442
return baseAddress!. loadUnaligned ( fromByteOffset: offset, as: T . self)
443
443
}
@@ -447,8 +447,8 @@ extension Unsafe${Mutable}RawBufferPointer {
447
447
fromByteOffset offset: Int = 0 ,
448
448
as type: T . Type
449
449
) -> T {
450
- _debugPrecondition ( offset >= 0 , " ${Self}.load with negative offset " )
451
- _debugPrecondition ( offset + MemoryLayout < T > . size <= self . count,
450
+ _boundsCheckPrecondition ( offset >= 0 , " ${Self}.load with negative offset " )
451
+ _boundsCheckPrecondition ( offset + MemoryLayout < T > . size <= self . count,
452
452
" ${Self}.load out of bounds " )
453
453
return baseAddress!. loadUnaligned ( fromByteOffset: offset, as: T . self)
454
454
}
@@ -495,8 +495,8 @@ extension Unsafe${Mutable}RawBufferPointer {
495
495
public func storeBytes< T> (
496
496
of value: T , toByteOffset offset: Int = 0 , as type: T . Type
497
497
) {
498
- _debugPrecondition ( offset >= 0 , " ${Self}.storeBytes with negative offset " )
499
- _debugPrecondition ( offset + MemoryLayout < T > . size <= self . count,
498
+ _boundsCheckPrecondition ( offset >= 0 , " ${Self}.storeBytes with negative offset " )
499
+ _boundsCheckPrecondition ( offset + MemoryLayout < T > . size <= self . count,
500
500
" ${Self}.storeBytes out of bounds " )
501
501
502
502
let pointer = baseAddress. _unsafelyUnwrappedUnchecked
@@ -511,8 +511,8 @@ extension Unsafe${Mutable}RawBufferPointer {
511
511
@usableFromInline func _legacy_se0349_storeBytes< T> (
512
512
of value: T , toByteOffset offset: Int = 0 , as type: T . Type
513
513
) {
514
- _debugPrecondition ( offset >= 0 , " ${Self}.storeBytes with negative offset " )
515
- _debugPrecondition ( offset + MemoryLayout < T > . size <= self . count,
514
+ _boundsCheckPrecondition ( offset >= 0 , " ${Self}.storeBytes with negative offset " )
515
+ _boundsCheckPrecondition ( offset + MemoryLayout < T > . size <= self . count,
516
516
" ${Self}.storeBytes out of bounds " )
517
517
518
518
baseAddress!. _legacy_se0349_storeBytes_internal (
@@ -538,7 +538,7 @@ extension Unsafe${Mutable}RawBufferPointer {
538
538
/// be less than or equal to this buffer's `count`.
539
539
@inlinable
540
540
public func copyMemory( from source: UnsafeRawBufferPointer ) {
541
- _debugPrecondition ( source. count <= self . count,
541
+ _boundsCheckPrecondition ( source. count <= self . count,
542
542
" ${Self}.copyMemory source has too many elements " )
543
543
if let baseAddress = baseAddress, let sourceAddress = source. baseAddress {
544
544
baseAddress. copyMemory ( from: sourceAddress, byteCount: source. count)
@@ -568,7 +568,7 @@ extension Unsafe${Mutable}RawBufferPointer {
568
568
569
569
if source. withContiguousStorageIfAvailable ( {
570
570
( buffer: UnsafeBufferPointer < UInt8 > ) -> Void in
571
- _debugPrecondition ( source. count <= self . count,
571
+ _boundsCheckPrecondition ( source. count <= self . count,
572
572
" ${Self}.copyBytes source has too many elements " )
573
573
if let base = buffer. baseAddress {
574
574
position. copyMemory ( from: base, byteCount: buffer. count)
@@ -578,7 +578,7 @@ extension Unsafe${Mutable}RawBufferPointer {
578
578
}
579
579
580
580
for (index, byteValue) in source. enumerated ( ) {
581
- _debugPrecondition ( index < self . count,
581
+ _boundsCheckPrecondition ( index < self . count,
582
582
" ${Self}.copyBytes source has too many elements " )
583
583
position. storeBytes (
584
584
of: byteValue, toByteOffset: index, as: UInt8 . self)
@@ -666,7 +666,7 @@ extension Unsafe${Mutable}RawBufferPointer {
666
666
// We only do this in debug builds to prevent a measurable performance
667
667
// degradation wrt passing around pointers not wrapped in a BufferPointer
668
668
// construct.
669
- _debugPrecondition (
669
+ _boundsCheckPrecondition (
670
670
slice. startIndex >= 0 && slice. endIndex <= slice. base. count,
671
671
" Invalid slice " )
672
672
let base = slice. base. baseAddress? . advanced ( by: slice. startIndex)
@@ -783,7 +783,7 @@ extension Unsafe${Mutable}RawBufferPointer {
783
783
let elementStride = MemoryLayout< S . Element> . stride
784
784
785
785
// This has to be a debug precondition due to the cost of walking over some collections.
786
- _debugPrecondition ( source. underestimatedCount <= ( count / elementStride) ,
786
+ _boundsCheckPrecondition ( source. underestimatedCount <= ( count / elementStride) ,
787
787
" insufficient space to accommodate source.underestimatedCount elements " )
788
788
guard let base = baseAddress else {
789
789
// this can be a precondition since only an invalid argument should be costly
@@ -792,7 +792,7 @@ extension Unsafe${Mutable}RawBufferPointer {
792
792
return ( it, UnsafeMutableBufferPointer ( start: nil , count: 0 ) )
793
793
}
794
794
795
- _debugPrecondition (
795
+ _boundsCheckPrecondition (
796
796
Int ( bitPattern: base) & ( MemoryLayout < S . Element > . alignment- 1 ) == 0 ,
797
797
" buffer base address must be properly aligned to access S.Element "
798
798
)
@@ -852,7 +852,7 @@ extension Unsafe${Mutable}RawBufferPointer {
852
852
guard let sourceAddress = $0. baseAddress, !$0. isEmpty else {
853
853
return . init( start: nil , count: 0 )
854
854
}
855
- _debugPrecondition (
855
+ _boundsCheckPrecondition (
856
856
Int ( bitPattern: baseAddress) & ( MemoryLayout < C . Element > . alignment- 1 ) == 0 ,
857
857
" buffer base address must be properly aligned to access C.Element "
858
858
)
@@ -877,7 +877,7 @@ extension Unsafe${Mutable}RawBufferPointer {
877
877
return . init( start: nil , count: 0 )
878
878
}
879
879
_internalInvariant ( _end != nil )
880
- _debugPrecondition (
880
+ _boundsCheckPrecondition (
881
881
Int ( bitPattern: baseAddress) & ( MemoryLayout < C . Element > . alignment- 1 ) == 0 ,
882
882
" buffer base address must be properly aligned to access C.Element "
883
883
)
@@ -939,7 +939,7 @@ extension Unsafe${Mutable}RawBufferPointer {
939
939
guard let sourceAddress = source. baseAddress, !source. isEmpty else {
940
940
return . init( start: nil , count: 0 )
941
941
}
942
- _debugPrecondition (
942
+ _boundsCheckPrecondition (
943
943
Int ( bitPattern: baseAddress) & ( MemoryLayout < T > . alignment- 1 ) == 0 ,
944
944
" buffer base address must be properly aligned to access T "
945
945
)
@@ -1081,7 +1081,7 @@ extension Unsafe${Mutable}RawBufferPointer {
1081
1081
guard let s = _position else {
1082
1082
return try body ( . init( start: nil , count: 0 ) )
1083
1083
}
1084
- _debugPrecondition (
1084
+ _boundsCheckPrecondition (
1085
1085
Int ( bitPattern: s) & ( MemoryLayout < T > . alignment- 1 ) == 0 ,
1086
1086
" baseAddress must be a properly aligned pointer for type T "
1087
1087
)
@@ -1134,7 +1134,7 @@ extension Unsafe${Mutable}RawBufferPointer {
1134
1134
try withMemoryRebound ( to: Element . self) { b in
1135
1135
var buffer = b
1136
1136
defer {
1137
- _debugPrecondition (
1137
+ _boundsCheckPrecondition (
1138
1138
( b. baseAddress, b. count) == ( buffer. baseAddress, buffer. count) ,
1139
1139
" UnsafeMutableRawBufferPointer.withContiguousMutableStorageIfAvailable: replacing the buffer is not allowed "
1140
1140
)
0 commit comments