@@ -286,24 +286,14 @@ extension ContiguousArray: RandomAccessCollection, MutableCollection {
286
286
@inlinable
287
287
public subscript( index: Int ) -> Element {
288
288
get {
289
- // This call may be hoisted or eliminated by the optimizer. If
290
- // there is an inout violation, this value may be stale so needs to be
291
- // checked again below.
292
- let wasNativeTypeChecked = _hoistableIsNativeTypeChecked ( )
293
-
294
- // Make sure the index is in range and wasNativeTypeChecked is
295
- // still valid.
296
- let token = _checkSubscript (
297
- index, wasNativeTypeChecked: wasNativeTypeChecked)
298
-
299
- return _getElement (
300
- index, wasNativeTypeChecked: wasNativeTypeChecked,
301
- matchingSubscriptCheck: token)
289
+ _checkSubscript_native ( index)
290
+ return _buffer. getElement ( index)
302
291
}
303
- mutableAddressWithNativeOwner {
304
- _makeMutableAndUnique ( ) // makes the array native, too
292
+ _modify {
293
+ _makeMutableAndUnique ( )
305
294
_checkSubscript_native ( index)
306
- return ( _getElementAddress ( index) , _getOwner_native ( ) )
295
+ let address = _buffer. subscriptBaseAddress + index
296
+ yield & address. pointee
307
297
}
308
298
}
309
299
@@ -353,17 +343,6 @@ extension ContiguousArray: RandomAccessCollection, MutableCollection {
353
343
354
344
//===--- private helpers---------------------------------------------------===//
355
345
extension ContiguousArray {
356
- /// Returns `true` if the array is native and does not need a deferred
357
- /// type check. May be hoisted by the optimizer, which means its
358
- /// results may be stale by the time they are used if there is an
359
- /// inout violation in user code.
360
- @inlinable
361
- @_semantics ( " array.props.isNativeTypeChecked " )
362
- public // @testable
363
- func _hoistableIsNativeTypeChecked( ) -> Bool {
364
- return _buffer. arrayPropertyIsNativeTypeChecked
365
- }
366
-
367
346
@inlinable
368
347
@_semantics ( " array.get_count " )
369
348
internal func _getCount( ) -> Int {
@@ -376,31 +355,6 @@ extension ContiguousArray {
376
355
return _buffer. capacity
377
356
}
378
357
379
- /// - Precondition: The array has a native buffer.
380
- @inlinable
381
- @_semantics ( " array.owner " )
382
- internal func _getOwnerWithSemanticLabel_native( ) -> Builtin . NativeObject {
383
- return Builtin . unsafeCastToNativeObject ( _buffer. nativeOwner)
384
- }
385
-
386
- /// - Precondition: The array has a native buffer.
387
- @inlinable
388
- @inline ( __always)
389
- internal func _getOwner_native( ) -> Builtin . NativeObject {
390
- #if _runtime(_ObjC)
391
- if _isClassOrObjCExistential ( Element . self) {
392
- // We are hiding the access to '_buffer.owner' behind
393
- // _getOwner() to help the compiler hoist uniqueness checks in
394
- // the case of class or Objective-C existential typed array
395
- // elements.
396
- return _getOwnerWithSemanticLabel_native ( )
397
- }
398
- #endif
399
- // In the value typed case the extra call to
400
- // _getOwnerWithSemanticLabel_native hinders optimization.
401
- return Builtin . unsafeCastToNativeObject ( _buffer. owner)
402
- }
403
-
404
358
@inlinable
405
359
@_semantics ( " array.make_mutable " )
406
360
internal mutating func _makeMutableAndUnique( ) {
@@ -417,22 +371,6 @@ extension ContiguousArray {
417
371
_buffer. _checkValidSubscript ( index)
418
372
}
419
373
420
- /// Check that the given `index` is valid for subscripting, i.e.
421
- /// `0 ≤ index < count`.
422
- @inlinable
423
- @_semantics ( " array.check_subscript " )
424
- public // @testable
425
- func _checkSubscript(
426
- _ index: Int , wasNativeTypeChecked: Bool
427
- ) -> _DependenceToken {
428
- #if _runtime(_ObjC)
429
- _buffer. _checkValidSubscript ( index)
430
- #else
431
- _buffer. _checkValidSubscript ( index)
432
- #endif
433
- return _DependenceToken ( )
434
- }
435
-
436
374
/// Check that the specified `index` is valid, i.e. `0 ≤ index ≤ count`.
437
375
@inlinable
438
376
@_semantics ( " array.check_index " )
@@ -441,21 +379,6 @@ extension ContiguousArray {
441
379
_precondition ( index >= startIndex, " Negative ContiguousArray index is out of range " )
442
380
}
443
381
444
- @_semantics ( " array.get_element " )
445
- @inline ( __always)
446
- public // @testable
447
- func _getElement(
448
- _ index: Int ,
449
- wasNativeTypeChecked: Bool ,
450
- matchingSubscriptCheck: _DependenceToken
451
- ) -> Element {
452
- #if false
453
- return _buffer. getElement ( index, wasNativeTypeChecked: wasNativeTypeChecked)
454
- #else
455
- return _buffer. getElement ( index)
456
- #endif
457
- }
458
-
459
382
@inlinable
460
383
@_semantics ( " array.get_element_address " )
461
384
internal func _getElementAddress( _ index: Int ) -> UnsafeMutablePointer < Element > {
0 commit comments