mirror of
https://github.com/apple/swift-collections
synced 2026-11-29 05:14:20 +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
@@ -176,19 +176,30 @@ extension RigidDeque where Element: ~Copyable {
|
||||
|
||||
@_lifetime(&self)
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maxCount: Int
|
||||
after index: inout Int
|
||||
) -> MutableSpan<Element> {
|
||||
_checkValidIndex(index)
|
||||
precondition(maxCount > 0, "maxCount must be positive")
|
||||
let segment = self._handle
|
||||
.nextSegment(after: index)
|
||||
._extracting(first: maxCount)
|
||||
let segment = self._handle.nextSegment(after: index)
|
||||
index &+= segment.count
|
||||
return _overrideLifetime(
|
||||
MutableSpan(_unsafeElements: .init(mutating: segment)),
|
||||
mutating: &self)
|
||||
}
|
||||
|
||||
@_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 segment = self._handle.nextSegment(
|
||||
after: &index, maxCount: maxCount, limitedBy: limit)
|
||||
return _overrideLifetime(
|
||||
MutableSpan(_unsafeElements: .init(mutating: segment)),
|
||||
mutating: &self)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public func spanBoundary(before index: Index) -> (index: Index, distance: Int) {
|
||||
precondition(index >= 0 && index <= count, "Index out of bounds")
|
||||
|
||||
@@ -115,9 +115,17 @@ extension UniqueDeque where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(&self)
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maxCount: Int
|
||||
after index: inout Int
|
||||
) -> MutableSpan<Element> {
|
||||
_storage.nextMutableSpan(after: &index, maxCount: maxCount)
|
||||
_storage.nextMutableSpan(after: &index)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(&self)
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maxCount: Int, limitedBy limit: Int
|
||||
) -> MutableSpan<Element> {
|
||||
_storage.nextMutableSpan(after: &index, maxCount: maxCount, limitedBy: limit)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
|
||||
Reference in new issue
Block a user