mirror of
https://github.com/apple/swift-collections
synced 2026-11-29 05:14:20 +00:00
Use Iterable from the Standard Library, replacing the local definition
This commit is contained in:
68 files changed
+565
-921
No files matched your search
@@ -314,12 +314,12 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
internal mutating func _append<
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
>(copying items: borrowing S) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeBorrowingIterator_()
|
||||
S: Iterable & ~Copyable & ~Escapable
|
||||
>(copying items: borrowing S) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
var it = items.makeBorrowingIterator()
|
||||
while true {
|
||||
let span = try it.nextSpan_()
|
||||
let span = try it.nextSpan()
|
||||
if span.isEmpty { break }
|
||||
self.append(copying: span)
|
||||
}
|
||||
@@ -337,10 +337,10 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `newElements`.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
public mutating func append<S: Iterable & ~Copyable & ~Escapable>(
|
||||
copying newElements: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._append(copying: newElements)
|
||||
}
|
||||
#endif
|
||||
@@ -380,11 +380,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<
|
||||
S: Iterable_ & Sequence<Element>
|
||||
S: Iterable & Sequence<Element>
|
||||
>(
|
||||
copying items: S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._append(copying: items)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,9 +23,7 @@ import ContainersPreview
|
||||
extension RigidDeque where Element: ~Copyable {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@frozen
|
||||
public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol_ {
|
||||
public typealias Element_ = Element
|
||||
|
||||
public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol {
|
||||
@usableFromInline
|
||||
internal var _currentSegment: Span<Element>
|
||||
|
||||
@@ -73,7 +71,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: copy self)
|
||||
public mutating func nextSpan_(maxCount: Int) -> Span<Element> {
|
||||
public mutating func nextSpan(maxCount: Int) -> Span<Element> {
|
||||
let result = _currentSegment._trim(first: maxCount)
|
||||
if _currentSegment.isEmpty {
|
||||
_currentSegment = _nextSegment
|
||||
@@ -86,7 +84,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(borrow self)
|
||||
public borrowing func makeBorrowingIterator_() -> BorrowingIterator {
|
||||
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
|
||||
BorrowingIterator(_deque: self)
|
||||
}
|
||||
#endif
|
||||
@@ -99,12 +97,12 @@ extension RigidDeque: Container where Element: ~Copyable {
|
||||
@_lifetime(borrow self)
|
||||
public func makeBorrowingIterator(
|
||||
from start: Index, to end: Index
|
||||
) -> BorrowingIterator_ {
|
||||
) -> BorrowingIterator {
|
||||
BorrowingIterator(_deque: self, from: start, to: end)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
|
||||
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
|
||||
// FIXME: This should validate that the iterator belongs to this deque.
|
||||
return iterator._position
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
public init<S: Iterable & ~Copyable & ~Escapable>(
|
||||
capacity: Int,
|
||||
copying contents: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
self.init(capacity: capacity)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
@@ -187,11 +187,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<S: Iterable_ & Sequence<Element>>(
|
||||
public init<S: Iterable & Sequence<Element>>(
|
||||
capacity: Int,
|
||||
copying contents: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
self.init(capacity: capacity)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
@@ -210,11 +210,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<S: Iterable_ & Collection<Element>>(
|
||||
public init<S: Iterable & Collection<Element>>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
self.init(capacity: capacity ?? contents.count)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
|
||||
@@ -366,12 +366,12 @@ extension RigidDeque /* where Element: Copyable */ {
|
||||
newCount: Int
|
||||
) {
|
||||
let expectedCount = self.count + newCount
|
||||
var it = items.makeBorrowingIterator_()
|
||||
var it = items.makeBorrowingIterator()
|
||||
insert(addingCount: newCount, at: index) { target in
|
||||
it._copyContents_(into: &target)
|
||||
it._copyContents(into: &target)
|
||||
}
|
||||
precondition(
|
||||
it.nextSpan_().isEmpty && self.count == expectedCount,
|
||||
it.nextSpan().isEmpty && self.count == expectedCount,
|
||||
"Broken Container: count doesn't match contents")
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -291,16 +291,16 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@inlinable
|
||||
internal mutating func _prepend<
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
S: Iterable & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
// We don't know the exact count of new elements, so we cannot initialize
|
||||
// them in place. Append them to the end of the deque first, then rotate
|
||||
// them to their correct location.
|
||||
//
|
||||
// FIXME: If we get a Iterable_.estimatedCount with an exact case,
|
||||
// FIXME: If we get a Iterable.estimatedCount with an exact case,
|
||||
// then we should use that when possible to copy items to their final
|
||||
// location in a single pass.
|
||||
let oldCount = self.count
|
||||
@@ -311,15 +311,15 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@inlinable
|
||||
internal mutating func _prepend<
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
S: Iterable & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying items: borrowing S,
|
||||
exactCount: Int
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeBorrowingIterator_()
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in
|
||||
let span = try it.nextSpan_(maxCount: target.freeCapacity)
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
var it = items.makeBorrowingIterator()
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure) in
|
||||
let span = try it.nextSpan(maxCount: target.freeCapacity)
|
||||
target._append(copying: span)
|
||||
}
|
||||
}
|
||||
@@ -340,10 +340,10 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
public mutating func prepend<S: Iterable & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
@@ -447,10 +447,10 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_ & Sequence<Element>>(
|
||||
public mutating func prepend<S: Iterable & Sequence<Element>>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
@@ -465,10 +465,10 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_ & Collection<Element>>(
|
||||
public mutating func prepend<S: Iterable & Collection<Element>>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._prepend(copying: items, exactCount: items.count)
|
||||
}
|
||||
|
||||
|
||||
@@ -467,12 +467,12 @@ extension RigidDeque /* where Element: Copyable */ {
|
||||
) {
|
||||
|
||||
let expectedCount = self.count - subrange.count + newCount
|
||||
var it = items.makeBorrowingIterator_()
|
||||
var it = items.makeBorrowingIterator()
|
||||
self.replace(removing: subrange, addingCount: newCount) { target in
|
||||
it._copyContents_(into: &target)
|
||||
it._copyContents(into: &target)
|
||||
}
|
||||
precondition(
|
||||
it.nextSpan_().isEmpty && count == expectedCount,
|
||||
it.nextSpan().isEmpty && count == expectedCount,
|
||||
"Broken Container: count doesn't match contents")
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -300,13 +300,13 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
internal mutating func _append<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
internal mutating func _append<S: Iterable & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeBorrowingIterator_()
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
var it = items.makeBorrowingIterator()
|
||||
while true {
|
||||
let span = try it.nextSpan_()
|
||||
let span = try it.nextSpan()
|
||||
if span.isEmpty { break }
|
||||
self.append(copying: span)
|
||||
}
|
||||
@@ -326,10 +326,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// over many similar invocations on the same deque
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
public mutating func append<S: Iterable & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._append(copying: items)
|
||||
}
|
||||
#endif
|
||||
@@ -378,10 +378,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// amortized over many similar invocations over the same deque.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<S: Iterable_ & Sequence<Element>>(
|
||||
public mutating func append<S: Iterable & Sequence<Element>>(
|
||||
copying items: S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._append(copying: items)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -26,7 +26,7 @@ extension UniqueDeque where Element: ~Copyable {
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(borrow self)
|
||||
public borrowing func makeBorrowingIterator_() -> BorrowingIterator {
|
||||
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
|
||||
BorrowingIterator(_deque: self._storage)
|
||||
}
|
||||
#endif
|
||||
@@ -39,13 +39,13 @@ extension UniqueDeque: Container where Element: ~Copyable {
|
||||
@_lifetime(borrow self)
|
||||
public func makeBorrowingIterator(
|
||||
from start: Index, to end: Index
|
||||
) -> BorrowingIterator_ {
|
||||
) -> BorrowingIterator {
|
||||
_storage.makeBorrowingIterator(from: start, to: end)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
|
||||
_storage.currentIndex(of: iterator)
|
||||
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
|
||||
_storage.currentIndex(of: &iterator)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -145,11 +145,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
public init<S: Iterable & ~Copyable & ~Escapable>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
self.init(minimumCapacity: capacity ?? 0)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
@@ -184,11 +184,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<S: Iterable_ & Sequence<Element>>(
|
||||
public init<S: Iterable & Sequence<Element>>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
self.init(minimumCapacity: capacity ?? contents.underestimatedCount)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
@@ -203,11 +203,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<S: Iterable_ & Collection<Element>>(
|
||||
public init<S: Iterable & Collection<Element>>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
self.init(minimumCapacity: capacity ?? contents.count)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
|
||||
@@ -384,12 +384,12 @@ extension UniqueDeque /* where Element: Copyable */ {
|
||||
newCount: Int
|
||||
) {
|
||||
let expectedCount = self.count + newCount
|
||||
var it = items.makeBorrowingIterator_()
|
||||
var it = items.makeBorrowingIterator()
|
||||
insert(addingCount: newCount, at: index) { target in
|
||||
it._copyContents_(into: &target)
|
||||
it._copyContents(into: &target)
|
||||
}
|
||||
precondition(
|
||||
it.nextSpan_().isEmpty && count == expectedCount,
|
||||
it.nextSpan().isEmpty && count == expectedCount,
|
||||
"Broken Container: count doesn't match contents")
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -322,10 +322,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@inlinable
|
||||
internal mutating func _prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
internal mutating func _prepend<S: Iterable & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element
|
||||
{
|
||||
// We don't know the exact count of new elements, so we cannot initialize
|
||||
// them in place. Append them to the end of the deque first, then rotate
|
||||
@@ -341,14 +341,14 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@inlinable
|
||||
internal mutating func _prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
internal mutating func _prepend<S: Iterable & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S,
|
||||
exactCount: Int
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeBorrowingIterator_()
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in
|
||||
let span = try it.nextSpan_(maxCount: target.freeCapacity)
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
var it = items.makeBorrowingIterator()
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure) in
|
||||
let span = try it.nextSpan(maxCount: target.freeCapacity)
|
||||
target._append(copying: span)
|
||||
}
|
||||
}
|
||||
@@ -370,10 +370,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// over many similar invocations on the same deque.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
public mutating func prepend<S: Iterable & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
@@ -483,10 +483,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// over many similar invocations on the same deque.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_ & Sequence<Element>>(
|
||||
public mutating func prepend<S: Iterable & Sequence<Element>>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
@@ -502,10 +502,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// over many similar invocations on the same deque.
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_ & Collection<Element>>(
|
||||
public mutating func prepend<S: Iterable & Collection<Element>>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
) throws(S.Failure)
|
||||
where S.Element == Element {
|
||||
try self._prepend(copying: items, exactCount: items.count)
|
||||
}
|
||||
|
||||
|
||||
@@ -476,12 +476,12 @@ extension UniqueDeque /* where Element: Copyable */ {
|
||||
) {
|
||||
|
||||
let expectedCount = self.count - subrange.count + newCount
|
||||
var it = items.makeBorrowingIterator_()
|
||||
var it = items.makeBorrowingIterator()
|
||||
self.replace(removing: subrange, addingCount: newCount) { target in
|
||||
it._copyContents_(into: &target)
|
||||
it._copyContents(into: &target)
|
||||
}
|
||||
precondition(
|
||||
it.nextSpan_().isEmpty && count == expectedCount,
|
||||
it.nextSpan().isEmpty && count == expectedCount,
|
||||
"Broken Container: count doesn't match contents")
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user