@@ -63,7 +63,7 @@ extension Span where Element: ~Copyable {
63
63
) {
64
64
_precondition (
65
65
( ( Int ( bitPattern: buffer. baseAddress) &
66
- ( MemoryLayout < Element > . alignment&- 1 ) ) == 0 ) ,
66
+ ( MemoryLayout < Element > . alignment &- 1 ) ) == 0 ) ,
67
67
" baseAddress must be properly aligned to access Element "
68
68
)
69
69
self . init ( _unchecked: buffer. baseAddress, count: buffer. count)
@@ -102,11 +102,11 @@ extension Span where Element: ~Copyable {
102
102
@_alwaysEmitIntoClient
103
103
@lifetime ( immortal)
104
104
public init (
105
- _unsafeStart start : UnsafePointer < Element > ,
105
+ _unsafeStart pointer : UnsafePointer < Element > ,
106
106
count: Int
107
107
) {
108
108
_precondition ( count >= 0 , " Count must not be negative " )
109
- self . init ( _unsafeElements: . init( start: start , count: count) )
109
+ self . init ( _unsafeElements: . init( start: pointer , count: count) )
110
110
}
111
111
}
112
112
@@ -177,12 +177,14 @@ extension Span where Element: BitwiseCopyable {
177
177
) {
178
178
_precondition (
179
179
( ( Int ( bitPattern: buffer. baseAddress) &
180
- ( MemoryLayout < Element > . alignment&- 1 ) ) == 0 ) ,
180
+ ( MemoryLayout < Element > . alignment &- 1 ) ) == 0 ) ,
181
181
" baseAddress must be properly aligned to access Element "
182
182
)
183
183
let ( byteCount, stride) = ( buffer. count, MemoryLayout< Element> . stride)
184
184
let ( count, remainder) = byteCount. quotientAndRemainder ( dividingBy: stride)
185
- _precondition ( remainder == 0 , " Span must contain a whole number of elements " )
185
+ _precondition (
186
+ remainder == 0 , " Span must contain a whole number of elements "
187
+ )
186
188
self . init ( _unchecked: buffer. baseAddress, count: count)
187
189
}
188
190
@@ -428,10 +430,13 @@ extension Span where Element: ~Copyable {
428
430
public subscript( unchecked position: Index ) -> Element {
429
431
//FIXME: change to unsafeRawAddress or unsafeAddress when ready
430
432
_read {
431
- let element = _start ( ) . advanced ( by: position&* MemoryLayout< Element> . stride)
432
- let binding = Builtin . bindMemory ( element. _rawValue, count. _builtinWordValue, Element . self)
433
- defer { Builtin . rebindMemory ( element. _rawValue, binding) }
434
- yield UnsafePointer < Element > ( element. _rawValue) . pointee
433
+ let elementOffset = position &* MemoryLayout< Element> . stride
434
+ let address = _start ( ) . advanced ( by: elementOffset)
435
+ let binding = Builtin . bindMemory (
436
+ address. _rawValue, 1 . _builtinWordValue, Element . self
437
+ )
438
+ defer { Builtin . rebindMemory ( address. _rawValue, binding) }
439
+ yield UnsafePointer < Element > ( address. _rawValue) . pointee
435
440
}
436
441
}
437
442
}
@@ -471,7 +476,8 @@ extension Span where Element: BitwiseCopyable {
471
476
@_alwaysEmitIntoClient
472
477
public subscript( unchecked position: Index ) -> Element {
473
478
get {
474
- let address = _start ( ) . advanced ( by: position&* MemoryLayout< Element> . stride)
479
+ let elementOffset = position &* MemoryLayout< Element> . stride
480
+ let address = _start ( ) . advanced ( by: elementOffset)
475
481
return address. loadUnaligned ( as: Element . self)
476
482
}
477
483
}
@@ -525,7 +531,7 @@ extension Span where Element: ~Copyable {
525
531
@unsafe
526
532
@_alwaysEmitIntoClient
527
533
public func _extracting( unchecked bounds: Range < Index > ) -> Self {
528
- let delta = bounds. lowerBound&* MemoryLayout< Element> . stride
534
+ let delta = bounds. lowerBound &* MemoryLayout< Element> . stride
529
535
return Span ( _unchecked: _pointer? . advanced ( by: delta) , count: bounds. count)
530
536
}
531
537
@@ -676,8 +682,8 @@ extension Span where Element: ~Copyable {
676
682
}
677
683
let start = _start ( )
678
684
let stride = MemoryLayout< Element> . stride
679
- let spanEnd = spanStart + stride&* span. _count
680
- if spanStart < start || spanEnd > ( start + stride&* _count) { return nil }
685
+ let spanEnd = spanStart + stride &* span. _count
686
+ if spanStart < start || spanEnd > ( start + stride &* _count) { return nil }
681
687
let byteOffset = start. distance ( to: spanStart)
682
688
let ( lower, r) = byteOffset. quotientAndRemainder ( dividingBy: stride)
683
689
guard r == 0 else { return nil }
@@ -732,7 +738,7 @@ extension Span where Element: ~Copyable {
732
738
public func _extracting( droppingLast k: Int ) -> Self {
733
739
_precondition ( k >= 0 , " Can't drop a negative number of elements. " )
734
740
let droppedCount = min ( k, count)
735
- return Self ( _unchecked: _pointer, count: count&- droppedCount)
741
+ return Self ( _unchecked: _pointer, count: count &- droppedCount)
736
742
}
737
743
738
744
/// Returns a span containing the final elements of the span,
@@ -755,7 +761,8 @@ extension Span where Element: ~Copyable {
755
761
public func _extracting( last maxLength: Int ) -> Self {
756
762
_precondition ( maxLength >= 0 , " Can't have a suffix of negative length. " )
757
763
let newCount = min ( maxLength, count)
758
- let newStart = _pointer? . advanced ( by: ( count&- newCount) * MemoryLayout< Element> . stride)
764
+ let offset = ( count &- newCount) * MemoryLayout< Element> . stride
765
+ let newStart = _pointer? . advanced ( by: offset)
759
766
return Self ( _unchecked: newStart, count: newCount)
760
767
}
761
768
@@ -778,7 +785,8 @@ extension Span where Element: ~Copyable {
778
785
public func _extracting( droppingFirst k: Int ) -> Self {
779
786
_precondition ( k >= 0 , " Can't drop a negative number of elements. " )
780
787
let droppedCount = min ( k, count)
781
- let newStart = _pointer? . advanced ( by: droppedCount*MemoryLayout< Element> . stride)
782
- return Self ( _unchecked: newStart, count: count&- droppedCount)
788
+ let offset = droppedCount * MemoryLayout< Element> . stride
789
+ let newStart = _pointer? . advanced ( by: offset)
790
+ return Self ( _unchecked: newStart, count: count &- droppedCount)
783
791
}
784
792
}
0 commit comments