Include notes about index mutation in span(after/before:)

The indexes passed to span(after:) and friends on UniqueArray
and RigidArray are modified before return. This adds notes
about the updated values to the method documentation, along
with a few other minor formatting changes (dropping smart
quotes, single-sentence abstracts).
This commit is contained in:
Nate Cook authored and Karoy Lorentey committed 2026-03-02 16:38:48 -08:00
1 parent aa337b4caf
commit 54ca53612f
28 files changed
+143 -109

No files matched your search

@@ -20,7 +20,7 @@ import ContainersPreview
@available(SwiftStdlib 5.0, *)
extension UniqueArray: BorrowingSequence where Element: ~Copyable {
public typealias BorrowingIterator = RigidArray<Element>.BorrowingIterator
public var estimatedCount: EstimatedCount {
.exactly(count)
}
@@ -62,7 +62,7 @@ extension UniqueArray where Element: ~Copyable {
/// start.
///
/// Valid indices consist of the position of every element and a "past the
/// end” position that’s not valid for use as a subscript argument.
/// end" position that's not valid for use as a subscript argument.
public typealias Index = Int
/// The position of the first element in a nonempty array. This is always zero.
@@ -72,7 +72,7 @@ extension UniqueArray where Element: ~Copyable {
@inline(__always)
public var startIndex: Int { _storage.startIndex }
/// The array’s "past the end” position—that is, the position one greater than
/// The array's "past the end" position—that is, the position one greater than
/// the last valid subscript argument. This is always equal to array's count.
///
/// - Complexity: O(1)
@@ -141,7 +141,7 @@ extension UniqueArray where Element: ~Copyable {
@_alwaysEmitIntoClient
@inline(__always)
public func index(after index: Int) -> Int { index + 1 }
/// Returns the position immediately before the given index.
///
/// - Note: To improve performance, this method does not validate that the
@@ -207,7 +207,7 @@ extension UniqueArray where Element: ~Copyable {
public func index(_ index: Int, offsetBy n: Int) -> Int {
index + n
}
/// Returns the distance between two indices.
///
/// - Note: To improve performance, this method does not validate that the
@@ -225,7 +225,7 @@ extension UniqueArray where Element: ~Copyable {
public func distance(from start: Index, to end: Index) -> Int {
end - start
}
/// Offsets the given index by the specified distance, but no further than
/// the given limiting index.
///
@@ -281,7 +281,7 @@ extension UniqueArray {
/// array at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the array’s `endIndex` as the `index`
/// specified index. If you pass the array's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// All existing elements at or following the specified position are moved to
@@ -311,7 +311,7 @@ extension UniqueArray {
/// array at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the array’s `endIndex` as the `index`
/// specified index. If you pass the array's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// All existing elements at or following the specified position are moved to
@@ -339,7 +339,7 @@ extension UniqueArray {
/// Copies the elements of a span into this array at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the array’s `endIndex` as the `index`
/// specified index. If you pass the array's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// All existing elements at or following the specified position are moved to
@@ -369,7 +369,7 @@ extension UniqueArray {
/// position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the array’s `endIndex` as the `index`
/// specified index. If you pass the array's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// All existing elements at or following the specified position are moved to
@@ -404,7 +404,7 @@ extension UniqueArray {
/// position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the array’s `endIndex` as the `index`
/// specified index. If you pass the array's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// All existing elements at or following the specified position are moved
@@ -436,7 +436,7 @@ extension UniqueArray {
/// position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the array’s `endIndex` as the `index`
/// specified index. If you pass the array's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// All existing elements at or following the specified position are moved to
@@ -130,6 +130,7 @@ extension UniqueArray where Element: ~Copyable {
extension UniqueArray where Element: ~Copyable {
/// Arbitrarily edit the storage underlying this array by invoking a
/// user-supplied closure with a mutable `OutputSpan` view over it.
///
/// This method calls its function argument at most once, allowing it to
/// arbitrarily modify the contents of the output span it is given.
/// The argument is free to add, remove or reorder any items; however,
@@ -158,10 +159,14 @@ extension UniqueArray where Element: ~Copyable {
@available(SwiftStdlib 5.0, *)
extension UniqueArray where Element: ~Copyable {
/// Return a borrowing span over the maximal storage chunk following the
/// specified position in the array. The span provides direct read-only access
/// to all array elements in the range `index ..< count`.
/// specified position in the array.
///
/// The returned span provides direct read-only access to all array elements
/// in the range `index ..< count`.
///
/// - Parameter index: A valid index in the array, including the end index.
/// When `span(after:)` returns, `index` is equal to the array's
/// `endIndex`.
///
/// - Complexity: O(1)
@inlinable
@@ -171,10 +176,14 @@ extension UniqueArray where Element: ~Copyable {
}
/// Return a borrowing span over the maximal storage chunk preceding the
/// specified position in the array. The span provides direct read-only access
/// to all array elements in the range `0 ..< index`.
/// specified position in the array.
///
/// The returned span provides direct read-only access to all array elements
/// in the range `0 ..< index`.
///
/// - Parameter index: A valid index in the array, including the end index.
/// When `span(before:)` returns, `index` is equal to the array's
/// `startIndex`.
///
/// - Complexity: O(1)
@inlinable
@@ -187,10 +196,14 @@ extension UniqueArray where Element: ~Copyable {
@available(SwiftStdlib 5.0, *)
extension UniqueArray where Element: ~Copyable {
/// Return a mutable span over the maximal storage chunk following the
/// specified position in the array. The span provides direct mutating access
/// to all array elements in the range `index ..< count`.
/// specified position in the array.
///
/// The returned span provides direct mutating access to all array elements
/// in the range `index ..< count`.
///
/// - Parameter index: A valid index in the array, including the end index.
/// When `mutableSpan(after:)` returns, `index` is equal to the array's
/// `endIndex`.
///
/// - Complexity: O(1)
@_lifetime(&self)
@@ -201,10 +214,14 @@ extension UniqueArray where Element: ~Copyable {
}
/// Return a mutable span over the maximal storage chunk preceding the specified
/// position in the array. The span provides direct mutating access to all
/// array elements in the range `0 ..< index`.
/// position in the array.
///
/// The returned span provides direct mutating access to all array elements
/// in the range `0 ..< index`.
///
/// - Parameter index: A valid index in the array, including the end index.
/// When `mutableSpan(before:)` returns, `index` is equal to the array's
/// `startIndex`.
///
/// - Complexity: O(1)
@_lifetime(&self)
@@ -291,7 +308,7 @@ extension UniqueArray {
public func clone() -> Self {
UniqueArray(consuming: _storage.clone())
}
/// Copy the contents of this array into a newly allocated unique array
/// instance with the specified capacity.
///