Introduce Container.nextSpan(after:maxCount:limitedBy:) and make it the core Container primitive

This commit is contained in:
Karoy Lorentey committed 2026-07-18 14:14:13 -07:00
1 parent 391693a8ba
commit e70b4df228
13 files changed
+290 -252

No files matched your search

@@ -354,10 +354,6 @@ extension RigidArray where Element: ~Copyable {
/// On return, `n` is set to zero if the operation succeeded without
/// hitting the limit; otherwise, `n` reflects the number of steps that
/// couldn't be taken.
/// - Parameter limit: A valid index of the array to use as a limit.
/// If `n > 0`, a limit that is less than `index` has no effect.
/// Likewise, if `n < 0`, a limit that is greater than `index` has no
/// effect.
/// - Complexity: O(1)
@_alwaysEmitIntoClient
public func formIndex(
@@ -366,6 +362,14 @@ extension RigidArray where Element: ~Copyable {
index._advance(by: &n, limitedBy: limit)
}
@inlinable
@_lifetime(borrow self)
public func nextSpan(
after index: inout Int
) -> Span<Element> {
self.span._nextSpan(after: &index)
}
/// Return a span over the array's storage that begins with the element at
/// the given index, and extends to the end of the contiguous storage chunk
/// that contains it, but no more than `maxCount` items.
@@ -429,6 +433,10 @@ extension RigidArray where Element: ~Copyable {
/// to process immediately. `maxCount` must be greater than zero.
/// If you are able to process an arbitrary number of items, set
/// `maxCount` to `Int.max`, or call the `nextSpan(after:)` method.
/// - Parameter limit: A valid index of the array to use as a limit.
/// If `n > 0`, a limit that is less than `index` has no effect.
/// Likewise, if `n < 0`, a limit that is greater than `index` has no
/// effect.
/// - Returns: A span over contiguous storage that starts at the given index.
/// If the input index is the end index, then this returns an empty span.
/// Otherwise the result is non-empty, with its first element matching the
@@ -437,17 +445,9 @@ extension RigidArray where Element: ~Copyable {
@inlinable
@_lifetime(borrow self)
public func nextSpan(
after index: inout Int, maxCount: Int
after index: inout Int, maxCount: Int, limitedBy limit: Index
) -> Span<Element> {
self.span._nextSpan(after: &index, maxCount: maxCount)
}
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public func nextSpan(
after index: inout Index, limitedBy limit: Index?
) -> Span<Element> {
self.span._nextSpan(after: &index, limitedBy: limit)
self.span._nextSpan(after: &index, maxCount: maxCount, limitedBy: limit)
}
@inlinable
@@ -21,7 +21,10 @@ extension RigidArray where Element: ~Copyable {
public func nextSpan(
after index: inout Int, maximumCount: Int
) -> Span<Element> {
self.nextSpan(after: &index, maxCount: maximumCount)
self.nextSpan(
after: &index,
maxCount: maximumCount,
limitedBy: self.endIndex)
}
@available(*, deprecated, renamed: "nextMutableSpan(after:maxCount:)")
@@ -387,17 +387,17 @@ extension UniqueArray where Element: ~Copyable {
@inlinable
@_lifetime(borrow self)
public func nextSpan(
after index: inout Int, maxCount: Int
after index: inout Int
) -> Span<Element> {
_storage.nextSpan(after: &index, maxCount: maxCount)
_storage.nextSpan(after: &index)
}
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public func nextSpan(
after index: inout Int, limitedBy limit: Int?
after index: inout Int, maxCount: Int, limitedBy limit: Int
) -> Span<Element> {
_storage.nextSpan(after: &index, limitedBy: limit)
_storage.nextSpan(after: &index, maxCount: maxCount, limitedBy: limit)
}
@inlinable
@@ -21,7 +21,10 @@ extension UniqueArray where Element: ~Copyable {
public func nextSpan(
after index: inout Int, maximumCount: Int
) -> Span<Element> {
self.nextSpan(after: &index, maxCount: maximumCount)
self.nextSpan(
after: &index,
maxCount: maximumCount,
limitedBy: self.endIndex)
}
@available(*, deprecated, renamed: "nextMutableSpan(after:maxCount:)")