mirror of
https://github.com/apple/swift-collections
synced 2026-11-26 04:47:48 +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
@@ -167,7 +167,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque where Element: ~Copyable {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
@_lifetime(&self)
|
||||
@@ -178,7 +178,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque where Element: ~Copyable {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@frozen
|
||||
public struct SubrangeConsumer: ~Copyable, ~Escapable {
|
||||
// FIXME: We have to use our own MutableRef because the standard one
|
||||
@@ -221,11 +221,11 @@ extension RigidDeque where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque.SubrangeConsumer: Drain where Element: ~Copyable {
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque.SubrangeConsumer where Element: ~Copyable {
|
||||
@inlinable
|
||||
public var count: Int {
|
||||
|
||||
@@ -77,10 +77,10 @@ extension RigidDeque: BidirectionalContainer where Element: ~Copyable {}
|
||||
extension RigidDeque: RandomAccessContainer where Element: ~Copyable {}
|
||||
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque: MutableContainer where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque: RangeReplaceableContainer where Element: ~Copyable {}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import InternalCollectionsUtilities
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension RigidDeque: Hashable where Element: Hashable & ~Copyable {
|
||||
}
|
||||
@@ -33,5 +34,19 @@ extension RigidDeque where Element: Hashable & ~Copyable {
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidDeque where Element: Hashable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(self.count)
|
||||
let segments = self._handle.segments()
|
||||
segments.first.span._hashContents(into: &hasher)
|
||||
if let second = segments.second {
|
||||
second.span._hashContents(into: &hasher)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -59,7 +59,13 @@ extension RigidDeque where Element: ~Copyable {
|
||||
precondition(!isEmpty, "Cannot remove first element of an empty RigidDeque")
|
||||
return _handle.uncheckedRemoveFirst()
|
||||
}
|
||||
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func _customRemoveLast() -> Element? {
|
||||
precondition(!isEmpty, "Cannot remove last element of an empty RigidDeque")
|
||||
return _handle.uncheckedRemoveLast()
|
||||
}
|
||||
|
||||
/// Removes and returns the last element of the deque.
|
||||
///
|
||||
/// The deque must not be empty.
|
||||
@@ -91,7 +97,15 @@ extension RigidDeque where Element: ~Copyable {
|
||||
precondition(k <= count, "Cannot remove more elements than there are in the container")
|
||||
_handle.uncheckedRemoveFirst(k)
|
||||
}
|
||||
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func _customRemoveLast(_ n: Int) -> Bool {
|
||||
precondition(n >= 0, "Cannot remove a negative number of elements")
|
||||
precondition(n <= count, "Cannot remove more elements than there are in the container")
|
||||
_handle.uncheckedRemoveLast(n)
|
||||
return true
|
||||
}
|
||||
|
||||
/// Removes and discards the specified number of elements from the end of the
|
||||
/// deque.
|
||||
///
|
||||
@@ -139,6 +153,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
return _handle.uncheckedRemoveFirst()
|
||||
}
|
||||
|
||||
#if !UnstableContainersPreview
|
||||
/// Removes and returns the last element of the deque, if there is one.
|
||||
///
|
||||
/// - Returns: The last element of the original deque if it was not empty;
|
||||
@@ -150,6 +165,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
guard !isEmpty else { return nil }
|
||||
return _handle.uncheckedRemoveLast()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -148,7 +148,7 @@ extension UniqueDeque where Element: ~Copyable {
|
||||
}
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDeque where Element: ~Copyable {
|
||||
public typealias SubrangeConsumer = RigidDeque<Element>.SubrangeConsumer
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@ extension UniqueDeque: RandomAccessContainer where Element: ~Copyable {}
|
||||
extension UniqueDeque: MutableContainer where Element: ~Copyable {}
|
||||
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDeque: RangeReplaceableContainer where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDeque: DynamicContainer where Element: ~Copyable {}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#if compiler(>=6.2)
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
extension UniqueDeque: Hashable where Element: Hashable & ~Copyable {
|
||||
}
|
||||
@@ -24,5 +25,14 @@ extension UniqueDeque where Element: Hashable & ~Copyable {
|
||||
self._storage.hash(into: &hasher)
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueDeque where Element: Hashable {
|
||||
@inlinable
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
self._storage.hash(into: &hasher)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -136,6 +136,7 @@ extension UniqueDeque where Element: ~Copyable {
|
||||
_storage.popFirst()
|
||||
}
|
||||
|
||||
#if !UnstableContainersPreview
|
||||
/// Removes and returns the last element of the deque, if there is one.
|
||||
///
|
||||
/// - Returns: The last element of the original deque if it was not empty;
|
||||
@@ -147,6 +148,7 @@ extension UniqueDeque where Element: ~Copyable {
|
||||
public mutating func popLast() -> Element? {
|
||||
_storage.popLast()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user