@@ -30,10 +30,10 @@ public struct Span<Element: ~Copyable & ~Escapable>
30
30
@_alwaysEmitIntoClient
31
31
@lifetime ( immortal)
32
32
internal init (
33
- _unchecked pointer: UnsafeRawPointer ? ,
33
+ _unchecked pointer: borrowing UnsafeRawPointer ? ,
34
34
count: Int
35
35
) {
36
- _pointer = pointer
36
+ _pointer = copy pointer
37
37
_count = count
38
38
}
39
39
}
@@ -59,14 +59,15 @@ extension Span where Element: ~Copyable {
59
59
@_alwaysEmitIntoClient
60
60
@lifetime ( immortal)
61
61
public init (
62
- _unsafeElements buffer: UnsafeBufferPointer < Element >
62
+ _unsafeElements buffer: borrowing UnsafeBufferPointer < Element >
63
63
) {
64
+ let baseAddress = buffer. baseAddress //FIXME: rdar://138665760
64
65
_precondition (
65
- ( ( Int ( bitPattern: buffer . baseAddress) &
66
+ ( ( Int ( bitPattern: baseAddress) &
66
67
( MemoryLayout < Element > . alignment &- 1 ) ) == 0 ) ,
67
68
" baseAddress must be properly aligned to access Element "
68
69
)
69
- self . init ( _unchecked: buffer . baseAddress, count: buffer. count)
70
+ self . init ( _unchecked: baseAddress, count: buffer. count)
70
71
}
71
72
72
73
/// Unsafely creates a `Span` over initialized memory.
@@ -82,7 +83,7 @@ extension Span where Element: ~Copyable {
82
83
@_alwaysEmitIntoClient
83
84
@lifetime ( immortal)
84
85
public init (
85
- _unsafeElements buffer: UnsafeMutableBufferPointer < Element >
86
+ _unsafeElements buffer: borrowing UnsafeMutableBufferPointer < Element >
86
87
) {
87
88
self . init ( _unsafeElements: UnsafeBufferPointer ( buffer) )
88
89
}
@@ -102,11 +103,11 @@ extension Span where Element: ~Copyable {
102
103
@_alwaysEmitIntoClient
103
104
@lifetime ( immortal)
104
105
public init (
105
- _unsafeStart pointer: UnsafePointer < Element > ,
106
+ _unsafeStart pointer: borrowing UnsafePointer < Element > ,
106
107
count: Int
107
108
) {
108
109
_precondition ( count >= 0 , " Count must not be negative " )
109
- self . init ( _unsafeElements: . init( start: pointer, count: count) )
110
+ self . init ( _unsafeElements: . init( start: copy pointer, count: count) )
110
111
}
111
112
}
112
113
@@ -127,7 +128,7 @@ extension Span {
127
128
@_alwaysEmitIntoClient
128
129
@lifetime ( immortal)
129
130
public init (
130
- _unsafeElements buffer: Slice < UnsafeBufferPointer < Element > >
131
+ _unsafeElements buffer: borrowing Slice < UnsafeBufferPointer < Element > >
131
132
) {
132
133
self . init ( _unsafeElements: UnsafeBufferPointer ( rebasing: buffer) )
133
134
}
@@ -145,7 +146,7 @@ extension Span {
145
146
@_alwaysEmitIntoClient
146
147
@lifetime ( immortal)
147
148
public init (
148
- _unsafeElements buffer: Slice < UnsafeMutableBufferPointer < Element > >
149
+ _unsafeElements buffer: borrowing Slice < UnsafeMutableBufferPointer < Element > >
149
150
) {
150
151
self . init ( _unsafeElements: UnsafeBufferPointer ( rebasing: buffer) )
151
152
}
@@ -173,10 +174,11 @@ extension Span where Element: BitwiseCopyable {
173
174
@_alwaysEmitIntoClient
174
175
@lifetime ( immortal)
175
176
public init (
176
- _unsafeBytes buffer: UnsafeRawBufferPointer
177
+ _unsafeBytes buffer: borrowing UnsafeRawBufferPointer
177
178
) {
179
+ let baseAddress = buffer. baseAddress //FIXME: rdar://138665760
178
180
_precondition (
179
- ( ( Int ( bitPattern: buffer . baseAddress) &
181
+ ( ( Int ( bitPattern: baseAddress) &
180
182
( MemoryLayout < Element > . alignment &- 1 ) ) == 0 ) ,
181
183
" baseAddress must be properly aligned to access Element "
182
184
)
@@ -185,7 +187,7 @@ extension Span where Element: BitwiseCopyable {
185
187
_precondition (
186
188
remainder == 0 , " Span must contain a whole number of elements "
187
189
)
188
- self . init ( _unchecked: buffer . baseAddress, count: count)
190
+ self . init ( _unchecked: baseAddress, count: count)
189
191
}
190
192
191
193
/// Unsafely creates a `Span` over initialized memory.
@@ -206,7 +208,7 @@ extension Span where Element: BitwiseCopyable {
206
208
@_alwaysEmitIntoClient
207
209
@lifetime ( immortal)
208
210
public init (
209
- _unsafeBytes buffer: UnsafeMutableRawBufferPointer
211
+ _unsafeBytes buffer: borrowing UnsafeMutableRawBufferPointer
210
212
) {
211
213
self . init ( _unsafeBytes: UnsafeRawBufferPointer ( buffer) )
212
214
}
@@ -230,11 +232,11 @@ extension Span where Element: BitwiseCopyable {
230
232
@_alwaysEmitIntoClient
231
233
@lifetime ( immortal)
232
234
public init (
233
- _unsafeStart pointer: UnsafeRawPointer ,
235
+ _unsafeStart pointer: borrowing UnsafeRawPointer ,
234
236
byteCount: Int
235
237
) {
236
238
_precondition ( byteCount >= 0 , " Count must not be negative " )
237
- self . init ( _unsafeBytes: . init( start: pointer, count: byteCount) )
239
+ self . init ( _unsafeBytes: . init( start: copy pointer, count: byteCount) )
238
240
}
239
241
240
242
/// Unsafely creates a `Span` over initialized memory.
@@ -255,7 +257,7 @@ extension Span where Element: BitwiseCopyable {
255
257
@_alwaysEmitIntoClient
256
258
@lifetime ( immortal)
257
259
public init (
258
- _unsafeBytes buffer: Slice < UnsafeRawBufferPointer >
260
+ _unsafeBytes buffer: borrowing Slice < UnsafeRawBufferPointer >
259
261
) {
260
262
self . init ( _unsafeBytes: UnsafeRawBufferPointer ( rebasing: buffer) )
261
263
}
@@ -278,7 +280,7 @@ extension Span where Element: BitwiseCopyable {
278
280
@_alwaysEmitIntoClient
279
281
@lifetime ( immortal)
280
282
public init (
281
- _unsafeBytes buffer: Slice < UnsafeMutableRawBufferPointer >
283
+ _unsafeBytes buffer: borrowing Slice < UnsafeMutableRawBufferPointer >
282
284
) {
283
285
self . init ( _unsafeBytes: UnsafeRawBufferPointer ( rebasing: buffer) )
284
286
}
0 commit comments