mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
Review and update container protocols and conformances
- @inlinable → @_alwaysEmitIntoClient for now, to avoid temporary ABI issues
- Review RangeReplaceableContainer algorithms; add missing ones:
- New requirements: `removeFirst()`, `removeFirst(_:)`, `_customRemoveLast()`, `_customRemoveLast(_:) (with default implementations)
- `func removeAll()`
- `func removeLast()`, `func removeLast(_:)`, `func popLast()` when self is also bidirectional
- Review RigidArray, UniqueArray algorithms; remove ones needlessly duplicating functionality already provided by RRC. Try not to break source compatibility.
This commit is contained in:
36 files changed
+415
-644
No files matched your search
@@ -132,6 +132,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
_storage.append(moving: &items)
|
||||
}
|
||||
|
||||
#if !UnstableContainersPreview
|
||||
/// Appends the elements of a given array to the end of this array by moving
|
||||
/// them between the containers. On return, the input array becomes empty, but
|
||||
/// it is not destroyed, and it preserves its original storage capacity.
|
||||
@@ -149,70 +150,19 @@ extension UniqueArray where Element: ~Copyable {
|
||||
public mutating func append(
|
||||
moving items: inout RigidArray<Element>
|
||||
) {
|
||||
// FIXME: Remove this in favor of a generic algorithm over range-replaceable containers
|
||||
_ensureFreeCapacity(items.count)
|
||||
_storage.append(moving: &items)
|
||||
items.edit { source in
|
||||
source.withUnsafeMutableBufferPointer { buffer, count in
|
||||
_storage.append(moving: buffer._extracting(first: count))
|
||||
count = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray where Element: ~Copyable {
|
||||
#if UnstableContainersPreview
|
||||
/// Appends the elements of a given container to the end of this array by
|
||||
/// consuming the source container.
|
||||
///
|
||||
/// If the target array does not have sufficient capacity to hold all items
|
||||
/// in the source array, then this automatically grows the target array's
|
||||
/// capacity, using a geometric growth rate.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - items: An array whose items to move to the end of this array.
|
||||
///
|
||||
/// - Complexity: O(`items.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append(
|
||||
consuming items: consuming RigidArray<Element>
|
||||
) {
|
||||
// FIXME: Remove this in favor of a generic algorithm over consumable containers
|
||||
var items = items
|
||||
self.append(moving: &items)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
/// Appends at most `newItemCount` items generated by a producer to the end of
|
||||
/// this array.
|
||||
///
|
||||
/// If the array doesn't have sufficient capacity to accommodate the specified
|
||||
/// number of new elements, then this method reallocates the array's storage
|
||||
/// to grow it, using a geometric growth rate.
|
||||
///
|
||||
/// This operation appends as many items as the producer can generate before
|
||||
/// either reaching its end (or throwing an error), or filling the specified
|
||||
/// capacity. This operation only consumes the first `newItemCount` items in the
|
||||
/// producer; if the producer has more, then they remain available after this
|
||||
/// method returns.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - newItemCount: The maximum number of items to append to the array.
|
||||
/// - producer: A producer that generates the items to append.
|
||||
///
|
||||
/// - Complexity: O(*n*) where *n* is the number of new items, when
|
||||
/// amortized over many similar invocations on the same array.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<
|
||||
E: Error,
|
||||
P: Producer<Element, E> & ~Copyable & ~Escapable
|
||||
>(
|
||||
addingCount newItemCount: Int,
|
||||
from producer: inout P
|
||||
) throws(E)
|
||||
where P.Element: ~Copyable
|
||||
{
|
||||
_ensureFreeCapacity(newItemCount)
|
||||
try _storage.append(addingCount: newItemCount, from: &producer)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
/// Appends all the items generated by a producer to the end of this deque.
|
||||
|
||||
Reference in new issue
Block a user