@@ -304,16 +304,15 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
304
304
305
305
@inlinable // unsafe-performance
306
306
public func _failEarlyRangeCheck( _ index: Int , bounds: Range < Int > ) {
307
- // NOTE: In release mode, this method is a no-op for performance reasons.
308
- _debugPrecondition ( index >= bounds. lowerBound)
309
- _debugPrecondition ( index < bounds. upperBound)
307
+ _boundsCheckPrecondition ( index >= bounds. lowerBound && index < bounds. upperBound)
310
308
}
311
309
312
310
@inlinable // unsafe-performance
313
311
public func _failEarlyRangeCheck( _ range: Range < Int > , bounds: Range < Int > ) {
314
- // NOTE: In release mode, this method is a no-op for performance reasons.
315
- _debugPrecondition ( range. lowerBound >= bounds. lowerBound)
316
- _debugPrecondition ( range. upperBound <= bounds. upperBound)
312
+ _boundsCheckPrecondition (
313
+ range. lowerBound >= bounds. lowerBound &&
314
+ range. upperBound <= bounds. upperBound
315
+ )
317
316
}
318
317
319
318
@inlinable // unsafe-performance
@@ -365,14 +364,14 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
365
364
@inlinable // unsafe-performance
366
365
public subscript( i: Int) -> Element {
367
366
get {
368
- _debugPrecondition ( i >= 0 )
369
- _debugPrecondition ( i < endIndex)
367
+ _boundsCheckPrecondition ( i >= 0 )
368
+ _boundsCheckPrecondition ( i < endIndex)
370
369
return _position. _unsafelyUnwrappedUnchecked [ i]
371
370
}
372
371
% if Mutable:
373
372
nonmutating _modify {
374
- _debugPrecondition ( i >= 0 )
375
- _debugPrecondition ( i < endIndex)
373
+ _boundsCheckPrecondition ( i >= 0 )
374
+ _boundsCheckPrecondition ( i < endIndex)
376
375
yield & _position. _unsafelyUnwrappedUnchecked [ i]
377
376
}
378
377
% end
@@ -438,16 +437,16 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
438
437
- > Slice< Unsafe ${ Mutable} BufferPointer< Element>>
439
438
{
440
439
get {
441
- _debugPrecondition ( bounds. lowerBound >= startIndex)
442
- _debugPrecondition ( bounds. upperBound <= endIndex)
440
+ _boundsCheckPrecondition ( bounds. lowerBound >= startIndex)
441
+ _boundsCheckPrecondition ( bounds. upperBound <= endIndex)
443
442
return Slice (
444
443
base: self , bounds: bounds)
445
444
}
446
445
% if Mutable:
447
446
nonmutating set {
448
- _debugPrecondition ( bounds. lowerBound >= startIndex)
449
- _debugPrecondition ( bounds. upperBound <= endIndex)
450
- _debugPrecondition ( bounds. count == newValue. count)
447
+ _boundsCheckPrecondition ( bounds. lowerBound >= startIndex)
448
+ _boundsCheckPrecondition ( bounds. upperBound <= endIndex)
449
+ _boundsCheckPrecondition ( bounds. count == newValue. count)
451
450
452
451
// FIXME: swift-3-indexing-model: tests.
453
452
if !newValue. isEmpty {
@@ -472,8 +471,8 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
472
471
@inlinable // unsafe-performance
473
472
public func swapAt( _ i: Int, _ j: Int) {
474
473
guard i != j else { return }
475
- _debugPrecondition ( i >= 0 && j >= 0 )
476
- _debugPrecondition ( i < endIndex && j < endIndex)
474
+ _boundsCheckPrecondition ( i >= 0 && j >= 0 )
475
+ _boundsCheckPrecondition ( i < endIndex && j < endIndex)
477
476
let pi = ( _position! + i)
478
477
let pj = ( _position! + j)
479
478
let tmp = pi. move ( )
@@ -554,7 +553,7 @@ extension Unsafe${Mutable}BufferPointer {
554
553
// We only do this in debug builds to prevent a measurable performance
555
554
// degradation wrt passing around pointers not wrapped in a BufferPointer
556
555
// construct.
557
- _debugPrecondition (
556
+ _boundsCheckPrecondition (
558
557
slice. startIndex >= 0 && slice. endIndex <= slice. base. count,
559
558
" Invalid slice " )
560
559
let base = slice. base. baseAddress? . advanced ( by: slice. startIndex)
@@ -1029,7 +1028,7 @@ extension Unsafe${Mutable}BufferPointer {
1029
1028
@inlinable
1030
1029
@_alwaysEmitIntoClient
1031
1030
public func initializeElement( at index: Index, to value: Element) {
1032
- _debugPrecondition ( startIndex <= index && index < endIndex)
1031
+ _boundsCheckPrecondition ( startIndex <= index && index < endIndex)
1033
1032
let p = baseAddress. _unsafelyUnwrappedUnchecked. advanced ( by: index)
1034
1033
p. initialize ( to: value)
1035
1034
}
@@ -1047,7 +1046,7 @@ extension Unsafe${Mutable}BufferPointer {
1047
1046
@inlinable
1048
1047
@_alwaysEmitIntoClient
1049
1048
public func moveElement( from index: Index) - > Element {
1050
- _debugPrecondition ( startIndex <= index && index < endIndex)
1049
+ _boundsCheckPrecondition ( startIndex <= index && index < endIndex)
1051
1050
return baseAddress. _unsafelyUnwrappedUnchecked. advanced ( by: index) . move ( )
1052
1051
}
1053
1052
@@ -1062,7 +1061,7 @@ extension Unsafe${Mutable}BufferPointer {
1062
1061
@inlinable
1063
1062
@_alwaysEmitIntoClient
1064
1063
public func deinitializeElement( at index: Index) {
1065
- _debugPrecondition ( startIndex <= index && index < endIndex)
1064
+ _boundsCheckPrecondition ( startIndex <= index && index < endIndex)
1066
1065
let p = baseAddress. _unsafelyUnwrappedUnchecked. advanced ( by: index)
1067
1066
p. deinitialize ( count: 1 )
1068
1067
}
0 commit comments