@@ -13,14 +13,14 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
13
13
14
14
/// Copies from a collection of `UInt8` into this buffer slice's memory.
15
15
///
16
- /// If the `source.count` bytes of memory referenced by this buffer are bound
17
- /// to a type `T`, then `T` must be a trivial type, the underlying pointer
18
- /// must be properly aligned for accessing `T`, and `source.count` must be a
19
- /// multiple of `MemoryLayout<T>.stride`.
16
+ /// If the first `source.count` bytes of memory referenced by
17
+ /// this buffer slice are bound to a type `T`, then `T` must be a trivial
18
+ /// type, the underlying pointer must be properly aligned for accessing `T`,
19
+ /// and `source.count` must be a multiple of `MemoryLayout<T>.stride`.
20
20
///
21
21
/// After calling `copyBytes(from:)`, the first `source.count` bytes of memory
22
- /// referenced by this buffer are initialized to raw bytes. If the memory is
23
- /// bound to type `T`, then it contains values of type `T`.
22
+ /// referenced by this buffer slice are initialized to raw bytes.
23
+ /// If the memory is bound to type `T`, then it contains values of type `T`.
24
24
///
25
25
/// - Parameter source: A collection of `UInt8` elements. `source.count` must
26
26
/// be less than or equal to this buffer slice's `count`.
@@ -31,20 +31,22 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
31
31
buffer. copyBytes ( from: source)
32
32
}
33
33
34
- /// Initializes the memory referenced by this buffer with the given value,
35
- /// binds the memory to the value's type, and returns a typed buffer of the
36
- /// initialized memory.
34
+ /// Initializes the memory referenced by this buffer slice with the given
35
+ /// value, binds the memory to the value's type, and returns a typed
36
+ /// buffer of the initialized memory.
37
37
///
38
- /// The memory referenced by this buffer must be uninitialized or
38
+ /// The memory referenced by this buffer slice must be uninitialized or
39
39
/// initialized to a trivial type, and must be properly aligned for
40
40
/// accessing `T`.
41
41
///
42
- /// After calling this method on a raw buffer with non-nil `baseAddress` `b`,
42
+ /// After calling this method on a raw buffer slice referencing memory
43
+ /// starting at `b = base.baseAddress + startIndex`,
43
44
/// the region starting at `b` and continuing up to
44
- /// `b + self.count - self.count % MemoryLayout<T>.stride` is bound to type `T` and
45
- /// initialized. If `T` is a nontrivial type, you must eventually deinitialize
46
- /// or move the values in this region to avoid leaks. If `baseAddress` is
47
- /// `nil`, this function does nothing and returns an empty buffer pointer.
45
+ /// `b + self.count - self.count % MemoryLayout<T>.stride` is bound
46
+ /// to type `T` and is initialized. If `T` is a nontrivial type, you must
47
+ /// eventually deinitialize or move the values in this region to avoid leaks.
48
+ /// If `base.baseAddress` is `nil`, this function does nothing
49
+ /// and returns an empty buffer pointer.
48
50
///
49
51
/// - Parameters:
50
52
/// - type: The type to bind this buffer’s memory to.
@@ -65,15 +67,15 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
65
67
/// Initializes the buffer's memory with the given elements, binding the
66
68
/// initialized memory to the elements' type.
67
69
///
68
- /// When calling the `initializeMemory(as:from:)` method on a buffer `b` ,
69
- /// the memory referenced by `b` must be uninitialized or initialized to a
70
- /// trivial type, and must be properly aligned for accessing `S.Element`.
70
+ /// When calling the `initializeMemory(as:from:)` method on a buffer slice ,
71
+ /// the memory referenced by the slice must be uninitialized or initialised
72
+ /// to a trivial type, and must be properly aligned for accessing `S.Element`.
71
73
/// The buffer must contain sufficient memory to accommodate
72
74
/// `source.underestimatedCount`.
73
75
///
74
- /// This method initializes the buffer with elements from `source` until
75
- /// `source` is exhausted or, if `source` is a sequence but not a
76
- /// collection, the buffer has no more room for its elements. After calling
76
+ /// This method initializes the buffer slice with elements from `source` until
77
+ /// `source` is exhausted or, if `source` is a sequence but not a collection,
78
+ /// the buffer slice has no more room for source's elements. After calling
77
79
/// `initializeMemory(as:from:)`, the memory referenced by the returned
78
80
/// `UnsafeMutableBufferPointer` instance is bound and initialized to type
79
81
/// `S.Element`.
@@ -203,11 +205,11 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
203
205
return buffer. moveInitializeMemory ( as: T . self, fromContentsOf: source)
204
206
}
205
207
206
- /// Binds this buffer’s memory to the specified type and returns a typed buffer
207
- /// of the bound memory.
208
+ /// Binds this buffer slice ’s memory to the specified type and returns
209
+ /// a typed buffer of the bound memory.
208
210
///
209
211
/// Use the `bindMemory(to:)` method to bind the memory referenced
210
- /// by this buffer to the type `T`. The memory must be uninitialized or
212
+ /// by this buffer slice to the type `T`. The memory must be uninitialized or
211
213
/// initialized to a type that is layout compatible with `T`. If the memory
212
214
/// is uninitialized, it is still uninitialized after being bound to `T`.
213
215
///
@@ -219,7 +221,8 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
219
221
/// - type: The type `T` to bind the memory to.
220
222
/// - Returns: A typed buffer of the newly bound memory. The memory in this
221
223
/// region is bound to `T`, but has not been modified in any other way.
222
- /// The typed buffer references `self.count / MemoryLayout<T>.stride` instances of `T`.
224
+ /// The typed buffer references `self.count / MemoryLayout<T>.stride`
225
+ /// instances of `T`.
223
226
@discardableResult
224
227
@inlinable
225
228
@_alwaysEmitIntoClient
@@ -228,10 +231,10 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
228
231
return buffer. bindMemory ( to: T . self)
229
232
}
230
233
231
- /// Executes the given closure while temporarily binding the buffer to
234
+ /// Executes the given closure while temporarily binding the buffer slice to
232
235
/// instances of type `T`.
233
236
///
234
- /// Use this method when you have a buffer to raw memory and you need
237
+ /// Use this method when you have a buffer slice to raw memory and you need
235
238
/// to access that memory as instances of a given type `T`. Accessing
236
239
/// memory as a type `T` requires that the memory be bound to that type.
237
240
/// A memory location may only be bound to one type at a time, so accessing
@@ -244,27 +247,27 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
244
247
/// uninitialized.) Accessing a `T` whose underlying memory
245
248
/// is in a mixed initialization state shall be undefined behaviour.
246
249
///
247
- /// If the byte count of the original buffer is not a multiple of
250
+ /// If the byte count of the original buffer slice is not a multiple of
248
251
/// the stride of `T`, then the re-bound buffer is shorter
249
252
/// than the original buffer.
250
253
///
251
254
/// After executing `body`, this method rebinds memory back to its original
252
255
/// binding state. This can be unbound memory, or bound to a different type.
253
256
///
254
- /// - Note: The buffer's base address must match the
255
- /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
256
- /// That is, `Int(bitPattern: self .baseAddress) % MemoryLayout<T>.alignment`
257
+ /// - Note: The buffer slice 's start address must match the
258
+ /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`). That is,
259
+ /// `Int(bitPattern: base .baseAddress+startIndex ) % MemoryLayout<T>.alignment`
257
260
/// must equal zero.
258
261
///
259
- /// - Note: A raw buffer may represent memory that has been bound to a type.
260
- /// If that is the case, then `T` must be layout compatible with the
262
+ /// - Note: A raw buffer slice may represent memory that has been bound to
263
+ /// a type. If that is the case, then `T` must be layout compatible with the
261
264
/// type to which the memory has been bound. This requirement does not
262
265
/// apply if the raw buffer represents memory that has not been bound
263
266
/// to any type.
264
267
///
265
268
/// - Parameters:
266
269
/// - type: The type to temporarily bind the memory referenced by this
267
- /// pointer. This pointer must be a multiple of this type's alignment .
270
+ /// buffer slice .
268
271
/// - body: A closure that takes a typed pointer to the
269
272
/// same memory as this pointer, only bound to type `T`. The closure's
270
273
/// pointer argument is valid only for the duration of the closure's
@@ -281,7 +284,7 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
281
284
return try buffer. withMemoryRebound ( to: T . self, body)
282
285
}
283
286
284
- /// Returns a typed buffer to the memory referenced by this buffer,
287
+ /// Returns a typed buffer to the memory referenced by this buffer slice ,
285
288
/// assuming that the memory is already bound to the specified type.
286
289
///
287
290
/// Use this method when you have a raw buffer to memory that has already
@@ -290,9 +293,9 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
290
293
/// pointer is undefined if the memory has not been bound to `T`. To bind
291
294
/// memory to `T`, use `bindMemory(to:capacity:)` instead of this method.
292
295
///
293
- /// - Note: The buffer's base address must match the
294
- /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
295
- /// That is, `Int(bitPattern: self .baseAddress) % MemoryLayout<T>.alignment`
296
+ /// - Note: The buffer slice 's start address must match the
297
+ /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`). That is,
298
+ /// `Int(bitPattern: base .baseAddress+startIndex ) % MemoryLayout<T>.alignment`
296
299
/// must equal zero.
297
300
///
298
301
/// - Parameter to: The type `T` that the memory has already been bound to.
@@ -430,11 +433,11 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
430
433
431
434
extension Slice where Base == UnsafeRawBufferPointer {
432
435
433
- /// Binds this buffer’s memory to the specified type and returns a typed buffer
434
- /// of the bound memory.
436
+ /// Binds this buffer slice ’s memory to the specified type and returns
437
+ /// a typed buffer of the bound memory.
435
438
///
436
439
/// Use the `bindMemory(to:)` method to bind the memory referenced
437
- /// by this buffer to the type `T`. The memory must be uninitialized or
440
+ /// by this buffer slice to the type `T`. The memory must be uninitialized or
438
441
/// initialized to a type that is layout compatible with `T`. If the memory
439
442
/// is uninitialized, it is still uninitialized after being bound to `T`.
440
443
///
@@ -446,7 +449,8 @@ extension Slice where Base == UnsafeRawBufferPointer {
446
449
/// - type: The type `T` to bind the memory to.
447
450
/// - Returns: A typed buffer of the newly bound memory. The memory in this
448
451
/// region is bound to `T`, but has not been modified in any other way.
449
- /// The typed buffer references `self.count / MemoryLayout<T>.stride` instances of `T`.
452
+ /// The typed buffer references `self.count / MemoryLayout<T>.stride`
453
+ /// instances of `T`.
450
454
@discardableResult
451
455
@inlinable
452
456
@_alwaysEmitIntoClient
@@ -455,10 +459,10 @@ extension Slice where Base == UnsafeRawBufferPointer {
455
459
return buffer. bindMemory ( to: T . self)
456
460
}
457
461
458
- /// Executes the given closure while temporarily binding the buffer to
462
+ /// Executes the given closure while temporarily binding the buffer slice to
459
463
/// instances of type `T`.
460
464
///
461
- /// Use this method when you have a buffer to raw memory and you need
465
+ /// Use this method when you have a buffer slice to raw memory and you need
462
466
/// to access that memory as instances of a given type `T`. Accessing
463
467
/// memory as a type `T` requires that the memory be bound to that type.
464
468
/// A memory location may only be bound to one type at a time, so accessing
@@ -471,27 +475,27 @@ extension Slice where Base == UnsafeRawBufferPointer {
471
475
/// uninitialized.) Accessing a `T` whose underlying memory
472
476
/// is in a mixed initialization state shall be undefined behaviour.
473
477
///
474
- /// If the byte count of the original buffer is not a multiple of
478
+ /// If the byte count of the original buffer slice is not a multiple of
475
479
/// the stride of `T`, then the re-bound buffer is shorter
476
480
/// than the original buffer.
477
481
///
478
482
/// After executing `body`, this method rebinds memory back to its original
479
483
/// binding state. This can be unbound memory, or bound to a different type.
480
484
///
481
- /// - Note: The buffer's base address must match the
482
- /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
483
- /// That is, `Int(bitPattern: self .baseAddress) % MemoryLayout<T>.alignment`
485
+ /// - Note: The buffer slice 's start address must match the
486
+ /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`). That is,
487
+ /// `Int(bitPattern: base .baseAddress+startIndex ) % MemoryLayout<T>.alignment`
484
488
/// must equal zero.
485
489
///
486
- /// - Note: A raw buffer may represent memory that has been bound to a type.
487
- /// If that is the case, then `T` must be layout compatible with the
490
+ /// - Note: A raw buffer slice may represent memory that has been bound to
491
+ /// a type. If that is the case, then `T` must be layout compatible with the
488
492
/// type to which the memory has been bound. This requirement does not
489
493
/// apply if the raw buffer represents memory that has not been bound
490
494
/// to any type.
491
495
///
492
496
/// - Parameters:
493
497
/// - type: The type to temporarily bind the memory referenced by this
494
- /// pointer. This pointer must be a multiple of this type's alignment .
498
+ /// buffer slice .
495
499
/// - body: A closure that takes a typed pointer to the
496
500
/// same memory as this pointer, only bound to type `T`. The closure's
497
501
/// pointer argument is valid only for the duration of the closure's
@@ -508,7 +512,7 @@ extension Slice where Base == UnsafeRawBufferPointer {
508
512
return try buffer. withMemoryRebound ( to: T . self, body)
509
513
}
510
514
511
- /// Returns a typed buffer to the memory referenced by this buffer,
515
+ /// Returns a typed buffer to the memory referenced by this buffer slice ,
512
516
/// assuming that the memory is already bound to the specified type.
513
517
///
514
518
/// Use this method when you have a raw buffer to memory that has already
@@ -517,9 +521,9 @@ extension Slice where Base == UnsafeRawBufferPointer {
517
521
/// pointer is undefined if the memory has not been bound to `T`. To bind
518
522
/// memory to `T`, use `bindMemory(to:capacity:)` instead of this method.
519
523
///
520
- /// - Note: The buffer's base address must match the
521
- /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`).
522
- /// That is, `Int(bitPattern: self .baseAddress) % MemoryLayout<T>.alignment`
524
+ /// - Note: The buffer slice 's start address must match the
525
+ /// alignment of `T` (as reported by `MemoryLayout<T>.alignment`). That is,
526
+ /// `Int(bitPattern: base .baseAddress+startIndex ) % MemoryLayout<T>.alignment`
523
527
/// must equal zero.
524
528
///
525
529
/// - Parameter to: The type `T` that the memory has already been bound to.
0 commit comments