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

@@ -188,7 +188,7 @@ extension Deque: RandomAccessCollection {
@inline(__always)
public var startIndex: Int { 0 }
/// The deque’s “past the end” position—that is, the position one greater than
/// The deque's "past the end" position—that is, the position one greater than
/// the last valid subscript argument.
///
/// For an instance of `Deque`, `endIndex` is always equal to its `count`. If
@@ -349,7 +349,7 @@ extension Deque: RandomAccessCollection {
/// than or equal to `startIndex` and less than `endIndex`.
///
/// - Complexity: Reading an element from a deque is O(1). Writing is O(1)
/// unless the deque’s storage is shared with another deque, in which case
/// unless the deque's storage is shared with another deque, in which case
/// writing is O(`count`).
@inlinable
public subscript(index: Int) -> Element {
@@ -743,7 +743,7 @@ extension Deque: RangeReplaceableCollection {
/// Inserts a new element at the specified position.
///
/// The new element is inserted before the element currently at the specified
/// index. If you pass the deque’s `endIndex` as the `index` parameter, the
/// index. If you pass the deque's `endIndex` as the `index` parameter, the
/// new element is appended to the deque.
///
/// - Parameters:
@@ -142,7 +142,7 @@ extension RigidDeque where Element: ~Copyable {
}
assert(remainder.isEmpty)
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Moves the elements of an input span into this deque,
/// starting at the specified position, and leaving the span empty.
@@ -173,7 +173,7 @@ extension RigidDeque where Element: ~Copyable {
}
}
#endif
/// Moves the elements of an output span into this deque,
/// starting at the specified position, and leaving the span empty.
///
@@ -259,7 +259,7 @@ extension RigidDeque /* where Element: Copyable */ {
/// deque at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -297,7 +297,7 @@ extension RigidDeque /* where Element: Copyable */ {
/// deque at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -325,7 +325,7 @@ extension RigidDeque /* where Element: Copyable */ {
/// Copies the elements of a span into this deque at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -391,13 +391,13 @@ extension RigidDeque /* where Element: Copyable */ {
precondition(i == items.endIndex,
"Broken Collection: count doesn't match contents")
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Copies the elements of a container into this deque at the specified
/// position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -429,7 +429,7 @@ extension RigidDeque /* where Element: Copyable */ {
/// position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -453,7 +453,7 @@ extension RigidDeque /* where Element: Copyable */ {
_insertCollection(
at: index, copying: items, newCount: items.count)
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Copies the elements of a container into this deque at the specified
/// position.
+11 -11
View File
@@ -133,7 +133,7 @@ public struct RigidDeque<Element: ~Copyable>: ~Copyable {
deinit {
_handle.dispose()
}
@inlinable @inline(__always)
package mutating func _takeHandle() -> _UnsafeHandle {
exchange(&_handle, with: .allocate(capacity: 0))
@@ -167,7 +167,7 @@ extension RigidDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public var capacity: Int { _assumeNonNegative(_handle.capacity) }
/// The number of additional elements that can be added to this deque without
/// exceeding its storage capacity.
///
@@ -175,7 +175,7 @@ extension RigidDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public var freeCapacity: Int { _assumeNonNegative(capacity &- count) }
/// A Boolean value indicating whether this rigid deque is fully populated.
/// If this property returns true, then the array's storage is at capacity,
/// and it cannot accommodate any additional elements.
@@ -194,31 +194,31 @@ extension RigidDeque where Element: ~Copyable {
/// logical start position.
///
/// 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
/// A Boolean value indicating whether this deque contains no elements.
///
/// - Complexity: O(1)
@_alwaysEmitIntoClient
@_transparent
public var isEmpty: Bool { _handle.count == 0 }
/// The number of elements in this deque.
///
/// - Complexity: O(1)
@_alwaysEmitIntoClient
@_transparent
public var count: Int { _handle.count }
/// The position of the first element in a nonempty deque. This is always zero.
///
/// - Complexity: O(1)
@_alwaysEmitIntoClient
@_transparent
public var startIndex: Int { 0 }
/// The deque’s "past the end” position—that is, the position one greater than
/// The deque's "past the end" position—that is, the position one greater than
/// the last valid subscript argument. This is always equal to the deque's
/// count.
///
@@ -226,7 +226,7 @@ extension RigidDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public var endIndex: Int { _handle.count }
/// The range of indices that are valid for subscripting this deque.
///
/// - Complexity: O(1)
@@ -316,7 +316,7 @@ extension RigidDeque where Element: ~Copyable {
public mutating func reallocate(capacity newCapacity: Int) {
_handle.reallocate(capacity: newCapacity)
}
/// Ensure that the deque has capacity to store the specified number of
/// elements, by growing its storage buffer if necessary.
///
@@ -148,7 +148,7 @@ extension UniqueDeque where Element: ~Copyable {
}
assert(remainder.isEmpty)
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Moves the elements of an input span into this deque,
/// starting at the specified position, and leaving the span empty.
@@ -181,7 +181,7 @@ extension UniqueDeque where Element: ~Copyable {
}
}
#endif
/// Moves the elements of an output span into this deque,
/// starting at the specified position, and leaving the span empty.
///
@@ -271,7 +271,7 @@ extension UniqueDeque /* where Element: Copyable */ {
/// deque at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the array.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -311,7 +311,7 @@ extension UniqueDeque /* where Element: Copyable */ {
/// deque at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -341,7 +341,7 @@ extension UniqueDeque /* where Element: Copyable */ {
/// Copies the elements of a span into this deque at the specified position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -410,13 +410,13 @@ extension UniqueDeque /* where Element: Copyable */ {
i == items.endIndex,
"Broken Collection: count doesn't match contents")
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Copies the elements of a container into this deque at the specified
/// position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -450,7 +450,7 @@ extension UniqueDeque /* where Element: Copyable */ {
/// position.
///
/// The new elements are inserted before the element currently at the
/// specified index. If you pass the deque’s `endIndex` as the `index`
/// specified index. If you pass the deque's `endIndex` as the `index`
/// parameter, then the new elements are appended to the end of the deque.
///
/// Existing elements in the deque's storage are moved as needed to make room
@@ -476,7 +476,7 @@ extension UniqueDeque /* where Element: Copyable */ {
_insertCollection(
at: index, copying: items, newCount: items.count)
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Copies the elements of a container into this deque at the specified
/// position.
@@ -103,7 +103,7 @@ public struct UniqueDeque<Element: ~Copyable>: ~Copyable {
public struct UniqueDeque<Element: ~Copyable>: ~Copyable {
@usableFromInline
package var _storage: RigidDeque<Element>
@_alwaysEmitIntoClient
@inline(__always)
package init(_storage: consuming RigidDeque<Element>) {
@@ -138,7 +138,7 @@ extension UniqueDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public var capacity: Int { _assumeNonNegative(_storage.capacity) }
/// The number of additional elements that can be added to this array without
/// reallocating its storage.
///
@@ -146,7 +146,7 @@ extension UniqueDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public var freeCapacity: Int { _assumeNonNegative(_storage.freeCapacity) }
@_alwaysEmitIntoClient
@_transparent
public var _isFull: Bool { _storage.isFull }
@@ -177,7 +177,7 @@ extension UniqueDeque where Element: ~Copyable {
@_transparent
public var startIndex: Int { _storage.startIndex }
/// The deque’s "past the end” position—that is, the position one greater than
/// The deque's "past the end" position—that is, the position one greater than
/// the last valid subscript argument. This is always equal to deque's count.
///
/// - Complexity: O(1)
@@ -270,14 +270,14 @@ extension UniqueDeque where Element: ~Copyable {
_storage.reserveCapacity(n)
}
@_alwaysEmitIntoClient
@_transparent
internal mutating func _ensureFreeCapacity(_ freeCapacity: Int) {
guard _storage.freeCapacity < freeCapacity else { return }
_ensureFreeCapacitySlow(freeCapacity)
}
@_alwaysEmitIntoClient
@_transparent
internal func _grow(freeCapacity: Int) -> Int {