@@ -201,28 +201,17 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
201
201
// NOTE: this is a manual specialization of index movement for a Strideable
202
202
// index that is required for UnsafeBufferPointer performance. The
203
203
// optimizer is not capable of creating partial specializations yet.
204
- // NOTE: Range checks are not performed here, because it is done later by
205
- // the subscript function.
206
- // NOTE: Wrapping math because we allow unsafe buffer pointers not to verify
207
- // index preconditions in release builds. Our (optimistic) assumption is
208
- // that the caller is already ensuring that indices are valid, so we can
209
- // elide the usual checks to help the optimizer generate better code.
210
- // However, we still check for overflow in debug mode.
211
204
let result = i. addingReportingOverflow ( 1 )
212
- _debugPrecondition ( !result. overflow)
205
+ _boundsCheckPrecondition ( !result. overflow)
213
206
return result. partialValue
214
207
}
215
208
216
209
@inlinable // unsafe-performance
217
210
public func formIndex( after i: inout Int ) {
218
211
// NOTE: this is a manual specialization of index movement for a Strideable
219
212
// index that is required for UnsafeBufferPointer performance. The
220
- // optimizer is not capable of creating partial specializations yet.
221
- // NOTE: Range checks are not performed here, because it is done later by
222
- // the subscript function.
223
- // See note on wrapping arithmetic in `index(after:)` above.
224
213
let result = i. addingReportingOverflow ( 1 )
225
- _debugPrecondition ( !result. overflow)
214
+ _boundsCheckPrecondition ( !result. overflow)
226
215
i = result. partialValue
227
216
}
228
217
@@ -231,11 +220,8 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
231
220
// NOTE: this is a manual specialization of index movement for a Strideable
232
221
// index that is required for UnsafeBufferPointer performance. The
233
222
// optimizer is not capable of creating partial specializations yet.
234
- // NOTE: Range checks are not performed here, because it is done later by
235
- // the subscript function.
236
- // See note on wrapping arithmetic in `index(after:)` above.
237
223
let result = i. subtractingReportingOverflow ( 1 )
238
- _debugPrecondition ( !result. overflow)
224
+ _boundsCheckPrecondition ( !result. overflow)
239
225
return result. partialValue
240
226
}
241
227
@@ -244,11 +230,8 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
244
230
// NOTE: this is a manual specialization of index movement for a Strideable
245
231
// index that is required for UnsafeBufferPointer performance. The
246
232
// optimizer is not capable of creating partial specializations yet.
247
- // NOTE: Range checks are not performed here, because it is done later by
248
- // the subscript function.
249
- // See note on wrapping arithmetic in `index(after:)` above.
250
233
let result = i. subtractingReportingOverflow ( 1 )
251
- _debugPrecondition ( !result. overflow)
234
+ _boundsCheckPrecondition ( !result. overflow)
252
235
i = result. partialValue
253
236
}
254
237
@@ -257,11 +240,8 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
257
240
// NOTE: this is a manual specialization of index movement for a Strideable
258
241
// index that is required for UnsafeBufferPointer performance. The
259
242
// optimizer is not capable of creating partial specializations yet.
260
- // NOTE: Range checks are not performed here, because it is done later by
261
- // the subscript function.
262
- // See note on wrapping arithmetic in `index(after:)` above.
263
243
let result = i. addingReportingOverflow ( n)
264
- _debugPrecondition ( !result. overflow)
244
+ _boundsCheckPrecondition ( !result. overflow)
265
245
return result. partialValue
266
246
}
267
247
@@ -270,19 +250,16 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
270
250
// NOTE: this is a manual specialization of index movement for a Strideable
271
251
// index that is required for UnsafeBufferPointer performance. The
272
252
// optimizer is not capable of creating partial specializations yet.
273
- // NOTE: Range checks are not performed here, because it is done later by
274
- // the subscript function.
275
- // See note on wrapping arithmetic in `index(after:)` above.
276
253
let maxOffset = limit. subtractingReportingOverflow ( i)
277
- _debugPrecondition ( !maxOffset. overflow)
254
+ _boundsCheckPrecondition ( !maxOffset. overflow)
278
255
let l = maxOffset. partialValue
279
256
280
257
if n > 0 ? l >= 0 && l < n : l <= 0 && n < l {
281
258
return nil
282
259
}
283
260
284
261
let result = i. addingReportingOverflow ( n)
285
- _debugPrecondition ( !result. overflow)
262
+ _boundsCheckPrecondition ( !result. overflow)
286
263
return result. partialValue
287
264
}
288
265
@@ -291,15 +268,13 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
291
268
// NOTE: this is a manual specialization of index movement for a Strideable
292
269
// index that is required for UnsafeBufferPointer performance. The
293
270
// optimizer is not capable of creating partial specializations yet.
294
- // NOTE: Range checks are not performed here, because it is done later by
295
- // the subscript function.
296
271
// NOTE: We allow the subtraction to silently overflow in release builds
297
272
// to eliminate a superfluous check when `start` and `end` are both valid
298
273
// indices. (The operation can only overflow if `start` is negative, which
299
274
// implies it's an invalid index.) `Collection` does not specify what
300
275
// `distance` should return when given an invalid index pair.
301
276
let result = end. subtractingReportingOverflow ( start)
302
- _debugPrecondition ( !result. overflow)
277
+ _boundsCheckPrecondition ( !result. overflow)
303
278
return result. partialValue
304
279
}
305
280
0 commit comments