Skip to content

Commit 4f8dd21

Browse files
committed
[se-0370] edit doc-comments for consistency
1 parent 88225a2 commit 4f8dd21

File tree

2 files changed

+69
-64
lines changed

2 files changed

+69
-64
lines changed

stdlib/public/core/UnsafeBufferPointerSlice.swift

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
1313

1414
/// Copies from a collection of `UInt8` into this buffer slice's memory.
1515
///
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`.
2020
///
2121
/// 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`.
2424
///
2525
/// - Parameter source: A collection of `UInt8` elements. `source.count` must
2626
/// be less than or equal to this buffer slice's `count`.
@@ -31,20 +31,22 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
3131
buffer.copyBytes(from: source)
3232
}
3333

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.
3737
///
38-
/// The memory referenced by this buffer must be uninitialized or
38+
/// The memory referenced by this buffer slice must be uninitialized or
3939
/// initialized to a trivial type, and must be properly aligned for
4040
/// accessing `T`.
4141
///
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`,
4344
/// 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.
4850
///
4951
/// - Parameters:
5052
/// - type: The type to bind this buffer’s memory to.
@@ -65,15 +67,15 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
6567
/// Initializes the buffer's memory with the given elements, binding the
6668
/// initialized memory to the elements' type.
6769
///
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`.
7173
/// The buffer must contain sufficient memory to accommodate
7274
/// `source.underestimatedCount`.
7375
///
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
7779
/// `initializeMemory(as:from:)`, the memory referenced by the returned
7880
/// `UnsafeMutableBufferPointer` instance is bound and initialized to type
7981
/// `S.Element`.
@@ -203,11 +205,11 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
203205
return buffer.moveInitializeMemory(as: T.self, fromContentsOf: source)
204206
}
205207

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.
208210
///
209211
/// 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
211213
/// initialized to a type that is layout compatible with `T`. If the memory
212214
/// is uninitialized, it is still uninitialized after being bound to `T`.
213215
///
@@ -219,7 +221,8 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
219221
/// - type: The type `T` to bind the memory to.
220222
/// - Returns: A typed buffer of the newly bound memory. The memory in this
221223
/// 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`.
223226
@discardableResult
224227
@inlinable
225228
@_alwaysEmitIntoClient
@@ -228,10 +231,10 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
228231
return buffer.bindMemory(to: T.self)
229232
}
230233

231-
/// Executes the given closure while temporarily binding the buffer to
234+
/// Executes the given closure while temporarily binding the buffer slice to
232235
/// instances of type `T`.
233236
///
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
235238
/// to access that memory as instances of a given type `T`. Accessing
236239
/// memory as a type `T` requires that the memory be bound to that type.
237240
/// A memory location may only be bound to one type at a time, so accessing
@@ -244,27 +247,27 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
244247
/// uninitialized.) Accessing a `T` whose underlying memory
245248
/// is in a mixed initialization state shall be undefined behaviour.
246249
///
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
248251
/// the stride of `T`, then the re-bound buffer is shorter
249252
/// than the original buffer.
250253
///
251254
/// After executing `body`, this method rebinds memory back to its original
252255
/// binding state. This can be unbound memory, or bound to a different type.
253256
///
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`
257260
/// must equal zero.
258261
///
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
261264
/// type to which the memory has been bound. This requirement does not
262265
/// apply if the raw buffer represents memory that has not been bound
263266
/// to any type.
264267
///
265268
/// - Parameters:
266269
/// - 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.
268271
/// - body: A closure that takes a typed pointer to the
269272
/// same memory as this pointer, only bound to type `T`. The closure's
270273
/// pointer argument is valid only for the duration of the closure's
@@ -281,7 +284,7 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
281284
return try buffer.withMemoryRebound(to: T.self, body)
282285
}
283286

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,
285288
/// assuming that the memory is already bound to the specified type.
286289
///
287290
/// Use this method when you have a raw buffer to memory that has already
@@ -290,9 +293,9 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
290293
/// pointer is undefined if the memory has not been bound to `T`. To bind
291294
/// memory to `T`, use `bindMemory(to:capacity:)` instead of this method.
292295
///
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`
296299
/// must equal zero.
297300
///
298301
/// - Parameter to: The type `T` that the memory has already been bound to.
@@ -430,11 +433,11 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
430433

431434
extension Slice where Base == UnsafeRawBufferPointer {
432435

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.
435438
///
436439
/// 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
438441
/// initialized to a type that is layout compatible with `T`. If the memory
439442
/// is uninitialized, it is still uninitialized after being bound to `T`.
440443
///
@@ -446,7 +449,8 @@ extension Slice where Base == UnsafeRawBufferPointer {
446449
/// - type: The type `T` to bind the memory to.
447450
/// - Returns: A typed buffer of the newly bound memory. The memory in this
448451
/// 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`.
450454
@discardableResult
451455
@inlinable
452456
@_alwaysEmitIntoClient
@@ -455,10 +459,10 @@ extension Slice where Base == UnsafeRawBufferPointer {
455459
return buffer.bindMemory(to: T.self)
456460
}
457461

458-
/// Executes the given closure while temporarily binding the buffer to
462+
/// Executes the given closure while temporarily binding the buffer slice to
459463
/// instances of type `T`.
460464
///
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
462466
/// to access that memory as instances of a given type `T`. Accessing
463467
/// memory as a type `T` requires that the memory be bound to that type.
464468
/// A memory location may only be bound to one type at a time, so accessing
@@ -471,27 +475,27 @@ extension Slice where Base == UnsafeRawBufferPointer {
471475
/// uninitialized.) Accessing a `T` whose underlying memory
472476
/// is in a mixed initialization state shall be undefined behaviour.
473477
///
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
475479
/// the stride of `T`, then the re-bound buffer is shorter
476480
/// than the original buffer.
477481
///
478482
/// After executing `body`, this method rebinds memory back to its original
479483
/// binding state. This can be unbound memory, or bound to a different type.
480484
///
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`
484488
/// must equal zero.
485489
///
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
488492
/// type to which the memory has been bound. This requirement does not
489493
/// apply if the raw buffer represents memory that has not been bound
490494
/// to any type.
491495
///
492496
/// - Parameters:
493497
/// - 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.
495499
/// - body: A closure that takes a typed pointer to the
496500
/// same memory as this pointer, only bound to type `T`. The closure's
497501
/// pointer argument is valid only for the duration of the closure's
@@ -508,7 +512,7 @@ extension Slice where Base == UnsafeRawBufferPointer {
508512
return try buffer.withMemoryRebound(to: T.self, body)
509513
}
510514

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,
512516
/// assuming that the memory is already bound to the specified type.
513517
///
514518
/// Use this method when you have a raw buffer to memory that has already
@@ -517,9 +521,9 @@ extension Slice where Base == UnsafeRawBufferPointer {
517521
/// pointer is undefined if the memory has not been bound to `T`. To bind
518522
/// memory to `T`, use `bindMemory(to:capacity:)` instead of this method.
519523
///
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`
523527
/// must equal zero.
524528
///
525529
/// - Parameter to: The type `T` that the memory has already been bound to.

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ extension Unsafe${Mutable}RawBufferPointer {
522522

523523
/// Copies from a collection of `UInt8` into this buffer's memory.
524524
///
525-
/// If the `source.count` bytes of memory referenced by this buffer are bound
526-
/// to a type `T`, then `T` must be a trivial type, the underlying pointer
527-
/// must be properly aligned for accessing `T`, and `source.count` must be a
528-
/// multiple of `MemoryLayout<T>.stride`.
525+
/// If the first `source.count` bytes of memory referenced by this buffer
526+
/// are bound to a type `T`, then `T` must be a trivial type,
527+
/// the underlying pointer must be properly aligned for accessing `T`,
528+
/// and `source.count` must be a multiple of `MemoryLayout<T>.stride`.
529529
///
530530
/// After calling `copyBytes(from:)`, the first `source.count` bytes of memory
531531
/// referenced by this buffer are initialized to raw bytes. If the memory is
@@ -697,7 +697,7 @@ extension Unsafe${Mutable}RawBufferPointer {
697697
/// After calling this method on a raw buffer with non-nil `baseAddress` `b`,
698698
/// the region starting at `b` and continuing up to
699699
/// `b + self.count - self.count % MemoryLayout<T>.stride` is bound
700-
/// to type `T` and initialized. If `T` is a nontrivial type, you must
700+
/// to type `T` and is initialized. If `T` is a nontrivial type, you must
701701
/// eventually deinitialize or move the values in this region to avoid leaks.
702702
/// If `baseAddress` is `nil`, this function does nothing
703703
/// and returns an empty buffer pointer.
@@ -733,8 +733,8 @@ extension Unsafe${Mutable}RawBufferPointer {
733733
/// `source.underestimatedCount`.
734734
///
735735
/// This method initializes the buffer with elements from `source` until
736-
/// `source` is exhausted or, if `source` is a sequence but not a
737-
/// collection, the buffer has no more room for its elements. After calling
736+
/// `source` is exhausted or, if `source` is a sequence but not a collection,
737+
/// the buffer has no more room for source's elements. After calling
738738
/// `initializeMemory(as:from:)`, the memory referenced by the returned
739739
/// `UnsafeMutableBufferPointer` instance is bound and initialized to type
740740
/// `S.Element`. This method does not change
@@ -977,7 +977,8 @@ extension Unsafe${Mutable}RawBufferPointer {
977977
/// - type: The type `T` to bind the memory to.
978978
/// - Returns: A typed buffer of the newly bound memory. The memory in this
979979
/// region is bound to `T`, but has not been modified in any other way.
980-
/// The typed buffer references `self.count / MemoryLayout<T>.stride` instances of `T`.
980+
/// The typed buffer references `self.count / MemoryLayout<T>.stride`
981+
/// instances of `T`.
981982
@_transparent
982983
@discardableResult
983984
public func bindMemory<T>(
@@ -1029,7 +1030,7 @@ extension Unsafe${Mutable}RawBufferPointer {
10291030
///
10301031
/// - Parameters:
10311032
/// - type: The type to temporarily bind the memory referenced by this
1032-
/// pointer. This pointer must be a multiple of this type's alignment.
1033+
/// buffer.
10331034
/// - body: A closure that takes a typed pointer to the
10341035
/// same memory as this pointer, only bound to type `T`. The closure's
10351036
/// pointer argument is valid only for the duration of the closure's

0 commit comments

Comments
 (0)