@@ -357,8 +357,29 @@ public protocol Sequence {
357
357
/// in the same order.
358
358
__consuming func _copyToContiguousArray( ) -> ContiguousArray < Element >
359
359
360
- /// Copy `self` into an unsafe buffer, returning a partially-consumed
361
- /// iterator with any elements that didn't fit remaining.
360
+ /// Copy `self` into an unsafe buffer, initializing its memory.
361
+ ///
362
+ /// The default implementation simply iterates over the elements of the
363
+ /// sequence, initializing the buffer one item at a time.
364
+ ///
365
+ /// For sequences whose elements are stored in contiguous chunks of memory,
366
+ /// it may be more efficient to copy them in bulk, using the
367
+ /// `UnsafeMutablePointer.initialize(from:count:)` method.
368
+ ///
369
+ /// - Parameter ptr: An unsafe buffer addressing uninitialized memory. The
370
+ /// buffer must be of sufficient size to accommodate
371
+ /// `source.underestimatedCount` elements. (Some implementations trap
372
+ /// if given a buffer that's smaller than this.)
373
+ ///
374
+ /// - Returns: `(it, c)`, where `c` is the number of elements copied into the
375
+ /// buffer, and `it` is a partially consumed iterator that can be used to
376
+ /// retrieve elements that did not fit into the buffer (if any). (This can
377
+ /// only happen if `underestimatedCount` turned out to be an actual
378
+ /// underestimate, and the buffer did not contain enough space to hold the
379
+ /// entire sequence.)
380
+ ///
381
+ /// On return, the memory region in `buffer[0 ..< c]` is initialized to
382
+ /// the first `c` elements in the sequence.
362
383
__consuming func _copyContents(
363
384
initializing ptr: UnsafeMutableBufferPointer < Element >
364
385
) -> ( Iterator , UnsafeMutableBufferPointer < Element > . Index )
@@ -1093,13 +1114,29 @@ extension Sequence {
1093
1114
}
1094
1115
1095
1116
extension Sequence {
1096
- /// Copies `self` into the supplied buffer.
1117
+ /// Copy `self` into an unsafe buffer, initializing its memory.
1118
+ ///
1119
+ /// The default implementation simply iterates over the elements of the
1120
+ /// sequence, initializing the buffer one item at a time.
1121
+ ///
1122
+ /// For sequences whose elements are stored in contiguous chunks of memory,
1123
+ /// it may be more efficient to copy them in bulk, using the
1124
+ /// `UnsafeMutablePointer.initialize(from:count:)` method.
1125
+ ///
1126
+ /// - Parameter ptr: An unsafe buffer addressing uninitialized memory. The
1127
+ /// buffer must be of sufficient size to accommodate
1128
+ /// `source.underestimatedCount` elements. (Some implementations trap
1129
+ /// if given a buffer that's smaller than this.)
1097
1130
///
1098
- /// - Precondition: The memory in `self` is uninitialized. The buffer must
1099
- /// contain sufficient uninitialized memory to accommodate `source.underestimatedCount`.
1131
+ /// - Returns: `(it, c)`, where `c` is the number of elements copied into the
1132
+ /// buffer, and `it` is a partially consumed iterator that can be used to
1133
+ /// retrieve elements that did not fit into the buffer (if any). (This can
1134
+ /// only happen if `underestimatedCount` turned out to be an actual
1135
+ /// underestimate, and the buffer did not contain enough space to hold the
1136
+ /// entire sequence.)
1100
1137
///
1101
- /// - Postcondition: The `Pointee`s at `buffer[startIndex ..<returned index ]` are
1102
- /// initialized .
1138
+ /// On return, the memory region in `buffer[0 ..< c ]` is initialized to
1139
+ /// the first `c` elements in the sequence .
1103
1140
@inlinable
1104
1141
public __consuming func _copyContents(
1105
1142
initializing buffer: UnsafeMutableBufferPointer < Element >
0 commit comments