mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
Update MutableContainer
- Add `nextMutableSpan(after:)` and `nextMutableSpan(after:maxCount:limitedBy)`, replacing `nextMutableSpan(after:maxCount:)` as the core access primitives - Add `previousMutableSpan` default algorithms on bidirectional mutable containers
This commit is contained in:
12 files changed
+350
-192
No files matched your search
@@ -453,13 +453,23 @@ extension RigidArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
@_lifetime(&self)
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maxCount: Int
|
||||
after index: inout Int
|
||||
) -> MutableSpan<Element> {
|
||||
_checkValidIndex(index)
|
||||
return _mutableSpan(in: Range(uncheckedBounds: (index, count)))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@_lifetime(&self)
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maxCount: Int, limitedBy limit: Int
|
||||
) -> MutableSpan<Element> {
|
||||
_checkValidIndex(index)
|
||||
_checkValidIndex(limit)
|
||||
precondition(maxCount > 0, "maxCount must be positive")
|
||||
let start = index
|
||||
index = start &+ Swift.min(maxCount, _count &- start)
|
||||
return _mutableSpan(in: Range(uncheckedBounds: (start, index)))
|
||||
let end = index._clampedUp(
|
||||
towards: count, maxDistance: maxCount, limitedBy: limit)
|
||||
return _mutableSpan(in: Range(uncheckedBounds: (index, end)))
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
|
||||
@@ -33,7 +33,10 @@ extension RigidArray where Element: ~Copyable {
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maximumCount: Int
|
||||
) -> MutableSpan<Element> {
|
||||
self.nextMutableSpan(after: &index, maxCount: maximumCount)
|
||||
self.nextMutableSpan(
|
||||
after: &index,
|
||||
maxCount: maximumCount,
|
||||
limitedBy: self.endIndex)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "previousSpan(before:maxCount:)")
|
||||
|
||||
@@ -403,9 +403,9 @@ extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
@_lifetime(&self)
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maxCount: Int
|
||||
after index: inout Int, maxCount: Int, limitedBy limit: Int
|
||||
) -> MutableSpan<Element> {
|
||||
_storage.nextMutableSpan(after: &index, maxCount: maxCount)
|
||||
_storage.nextMutableSpan(after: &index, maxCount: maxCount, limitedBy: limit)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
|
||||
@@ -33,7 +33,10 @@ extension UniqueArray where Element: ~Copyable {
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maximumCount: Int
|
||||
) -> MutableSpan<Element> {
|
||||
self.nextMutableSpan(after: &index, maxCount: maximumCount)
|
||||
self.nextMutableSpan(
|
||||
after: &index,
|
||||
maxCount: maximumCount,
|
||||
limitedBy: self.endIndex)
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "previousSpan(before:maxCount:)")
|
||||
|
||||
Reference in new issue
Block a user