mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
Review error handling
This commit is contained in:
16 files changed
+148
-126
No files matched your search
@@ -349,10 +349,11 @@ extension RigidArray {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@inlinable
|
||||
internal mutating func _append<
|
||||
Source: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
Source: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying newElements: borrowing Source
|
||||
) throws(E) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
let target = _freeSpace
|
||||
_count += try newElements._copyContents(intoPrefixOf: target)
|
||||
}
|
||||
@@ -371,10 +372,11 @@ extension RigidArray {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func append<
|
||||
Source: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
Source: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying newElements: borrowing Source
|
||||
) throws(E) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
try _append(copying: newElements)
|
||||
}
|
||||
#endif
|
||||
@@ -413,9 +415,12 @@ extension RigidArray {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func append<
|
||||
Source: Iterable_<Element, Never> & Sequence<Element>
|
||||
>(copying newElements: Source) {
|
||||
_append(copying: newElements)
|
||||
Source: Iterable_ & Sequence<Element>
|
||||
>(
|
||||
copying newElements: Source
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
try _append(copying: newElements)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -124,10 +124,11 @@ extension RigidArray /*where Element: Copyable*/ {
|
||||
/// The container must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<Source: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
|
||||
public init<Source: Iterable_ & ~Copyable & ~Escapable>(
|
||||
capacity: Int,
|
||||
copying contents: borrowing Source
|
||||
) throws(E) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
self.init(capacity: capacity)
|
||||
try self.append(copying: contents)
|
||||
}
|
||||
@@ -145,12 +146,13 @@ extension RigidArray /*where Element: Copyable*/ {
|
||||
/// The container must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<Source: Iterable_<Element, Never> & Sequence<Element>>(
|
||||
public init<Source: Iterable_ & Sequence<Element>>(
|
||||
capacity: Int,
|
||||
copying contents: Source
|
||||
) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
self.init(capacity: capacity)
|
||||
self.append(copying: contents)
|
||||
try self.append(copying: contents)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -120,25 +120,27 @@ extension RigidSet /* where Element: Copyable */ {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
S: Iterable_ & Sequence<Element>
|
||||
>(
|
||||
capacity: Int,
|
||||
copying contents: borrowing S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(capacity: capacity)
|
||||
self._insert(copying: contents)
|
||||
try self._insert(copying: contents)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, Never> & Collection<Element>
|
||||
S: Iterable_ & Collection<Element>
|
||||
>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(capacity: capacity ?? contents.count)
|
||||
self._insert(copying: contents)
|
||||
try self._insert(copying: contents)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -223,11 +223,11 @@ extension RigidSet /* where Element: Copyable */ {
|
||||
#if UnstableContainersPreview
|
||||
@_alwaysEmitIntoClient
|
||||
package mutating func _insert<
|
||||
Failure: Error,
|
||||
S: Iterable_<Element, Failure> & ~Copyable & ~Escapable
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeIterableIterator_()
|
||||
while true {
|
||||
let span = try it.nextSpan_()
|
||||
@@ -263,11 +263,12 @@ extension RigidSet /* where Element: Copyable */ {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
S: Iterable_ & Sequence<Element>
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
_insert(copying: items)
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try _insert(copying: items)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -310,10 +310,11 @@ extension UniqueArray {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@inlinable
|
||||
internal mutating func _append<
|
||||
Source: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
Source: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying newElements: borrowing Source
|
||||
) throws(E) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
_ensureFreeCapacity(newElements.underestimatedCount_)
|
||||
var it = newElements.makeIterableIterator_()
|
||||
while true {
|
||||
@@ -343,10 +344,11 @@ extension UniqueArray {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func append<
|
||||
Source: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
Source: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying newElements: borrowing Source
|
||||
) throws(E) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
try self._append(copying: newElements)
|
||||
}
|
||||
|
||||
@@ -397,9 +399,12 @@ extension UniqueArray {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func append<
|
||||
Source: Iterable_<Element, Never> & Sequence<Element>
|
||||
>(copying newElements: Source) {
|
||||
self._append(copying: newElements)
|
||||
Source: Iterable_ & Sequence<Element>
|
||||
>(
|
||||
copying newElements: Source
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
try self._append(copying: newElements)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -96,10 +96,11 @@ extension UniqueArray /*where Element: Copyable*/ {
|
||||
/// The sequence must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<Source: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
|
||||
public init<Source: Iterable_ & ~Copyable & ~Escapable>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: borrowing Source
|
||||
) throws(E) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
self.init(minimumCapacity: capacity ?? 0)
|
||||
try self.append(copying: contents)
|
||||
}
|
||||
@@ -132,12 +133,13 @@ extension UniqueArray /*where Element: Copyable*/ {
|
||||
/// - contents: The container whose contents to copy into the new array.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<Source: Iterable_<Element, Never> & Sequence<Element>>(
|
||||
public init<Source: Iterable_ & Sequence<Element>>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: Source
|
||||
) {
|
||||
) throws(Source.Failure_)
|
||||
where Source.Element_ == Element {
|
||||
self.init(minimumCapacity: capacity ?? 0)
|
||||
self.append(copying: contents)
|
||||
try self.append(copying: contents)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -96,12 +96,13 @@ extension UniqueSet where Element: Copyable {
|
||||
#if UnstableContainersPreview
|
||||
@_alwaysEmitIntoClient
|
||||
public init<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
S: Iterable_ & Sequence<Element>
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init()
|
||||
self._insert(copying: items)
|
||||
try self._insert(copying: items)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -173,11 +173,12 @@ extension UniqueSet /* where Element: Copyable */ {
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
S: Iterable_ & Sequence<Element>
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
_insert(copying: items)
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try _insert(copying: items)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -427,11 +427,11 @@ where
|
||||
|
||||
@inlinable
|
||||
public mutating func append<
|
||||
Failure: Error,
|
||||
S: Iterable_<Element, Failure> & ~Copyable & ~Escapable
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) throws(Failure) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeIterableIterator_()
|
||||
while true {
|
||||
let span = try it.nextSpan_()
|
||||
|
||||
@@ -25,9 +25,9 @@ where
|
||||
/// will get copied.
|
||||
@inlinable
|
||||
@_lifetime(copy self)
|
||||
public consuming func copy() -> BorrowingMapProducer<Self, Element_, Never> {
|
||||
public consuming func copy() -> BorrowingMapProducer<Self, Element_> {
|
||||
// FIXME: We could also just define a direct implementation that avoids the closure.
|
||||
BorrowingMapProducer(_base: self, transform: { $0 })
|
||||
self.map { $0 }
|
||||
}
|
||||
|
||||
// Note: We could also define `collect(into:)` directly on borrowing iterators,
|
||||
|
||||
@@ -313,8 +313,9 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@_alwaysEmitIntoClient
|
||||
internal mutating func _append<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(copying items: borrowing S) throws(E) {
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
>(copying items: borrowing S) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeIterableIterator_()
|
||||
while true {
|
||||
let span = try it.nextSpan_()
|
||||
@@ -334,9 +335,10 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
///
|
||||
/// - Complexity: O(*m*), where *m* is the length of `newElements`.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<S: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
|
||||
public mutating func append<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
copying newElements: borrowing S
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._append(copying: newElements)
|
||||
}
|
||||
#endif
|
||||
@@ -375,10 +377,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`. @available(SwiftStdlib 5.0, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
>(
|
||||
S: Iterable_ & Sequence<Element>
|
||||
>(
|
||||
copying items: S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._append(copying: items)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -131,12 +131,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// The sequence must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(
|
||||
public init<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
capacity: Int,
|
||||
copying contents: borrowing S
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(capacity: capacity)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
@@ -186,14 +185,13 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// The sequence must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
>(
|
||||
public init<S: Iterable_ & Sequence<Element>>(
|
||||
capacity: Int,
|
||||
copying contents: borrowing S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(capacity: capacity)
|
||||
self._append(copying: contents)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
|
||||
/// Creates a new deque with the specified capacity, holding a copy
|
||||
@@ -207,14 +205,13 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
/// The sequence must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, Never> & Collection<Element>
|
||||
>(
|
||||
public init<S: Iterable_ & Collection<Element>>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(capacity: capacity ?? contents.count)
|
||||
self._append(copying: contents)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -290,8 +290,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@inlinable
|
||||
internal mutating func _prepend<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(copying items: borrowing S) throws(E) {
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying items: borrowing S
|
||||
) 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.
|
||||
@@ -306,13 +309,14 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
|
||||
@inlinable
|
||||
internal mutating func _prepend<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
S: Iterable_ & ~Copyable & ~Escapable
|
||||
>(
|
||||
copying items: borrowing S,
|
||||
exactCount: Int
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeIterableIterator_()
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(E) in
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in
|
||||
let span = try it.nextSpan_(maximumCount: target.freeCapacity)
|
||||
target._append(copying: span)
|
||||
}
|
||||
@@ -333,9 +337,10 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
///
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
|
||||
public mutating func prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
@@ -437,10 +442,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
///
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_<Element, Never> & Sequence<Element>>(
|
||||
public mutating func prepend<S: Iterable_ & Sequence<Element>>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
self._prepend(copying: items)
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
/// Copies the elements of a borrowing sequence to the front of this deque.
|
||||
@@ -453,10 +459,11 @@ extension RigidDeque /*where Element: Copyable*/ {
|
||||
///
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<S: Iterable_<Element, Never> & Collection<Element>>(
|
||||
public mutating func prepend<S: Iterable_ & Collection<Element>>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
self._prepend(copying: items, exactCount: items.count)
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._prepend(copying: items, exactCount: items.count)
|
||||
}
|
||||
|
||||
/// Copies the elements of a container to the front of this deque.
|
||||
|
||||
@@ -299,9 +299,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@_alwaysEmitIntoClient
|
||||
internal mutating func _append<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(copying items: borrowing S) throws(E) {
|
||||
internal mutating func _append<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeIterableIterator_()
|
||||
while true {
|
||||
let span = try it.nextSpan_()
|
||||
@@ -323,9 +324,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`, when amortized
|
||||
/// over many similar invocations on the same deque
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<S: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
|
||||
public mutating func append<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._append(copying: items)
|
||||
}
|
||||
#endif
|
||||
@@ -373,11 +375,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`, when
|
||||
/// amortized over many similar invocations over the same deque.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
>(
|
||||
public mutating func append<S: Iterable_ & Sequence<Element>>(
|
||||
copying items: S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._append(copying: items)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -144,12 +144,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// - contents: A sequence whose contents to copy into the new deque.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(
|
||||
public init<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: borrowing S
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(minimumCapacity: capacity ?? 0)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
@@ -183,14 +182,13 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// The sequence must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
>(
|
||||
public init<S: Iterable_ & Sequence<Element>>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(minimumCapacity: capacity ?? contents.underestimatedCount)
|
||||
self._append(copying: contents)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
|
||||
/// Creates a new deque with the specified capacity, holding a copy
|
||||
@@ -202,14 +200,13 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// The sequence must not contain more than `capacity` elements.
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<
|
||||
S: Iterable_<Element, Never> & Collection<Element>
|
||||
>(
|
||||
public init<S: Iterable_ & Collection<Element>>(
|
||||
capacity: Int? = nil,
|
||||
copying contents: S
|
||||
) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
self.init(minimumCapacity: capacity ?? contents.count)
|
||||
self._append(copying: contents)
|
||||
try self._append(copying: contents)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -321,9 +321,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@inlinable
|
||||
internal mutating func _prepend<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(copying items: borrowing S) throws(E) {
|
||||
internal mutating func _prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) 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.
|
||||
@@ -337,14 +339,13 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
internal mutating func _prepend<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(
|
||||
internal mutating func _prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S,
|
||||
exactCount: Int
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
var it = items.makeIterableIterator_()
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(E) in
|
||||
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in
|
||||
let span = try it.nextSpan_(maximumCount: target.freeCapacity)
|
||||
target._append(copying: span)
|
||||
}
|
||||
@@ -366,11 +367,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`, as amortized
|
||||
/// over many similar invocations on the same deque.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<
|
||||
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
|
||||
>(
|
||||
public mutating func prepend<S: Iterable_ & ~Copyable & ~Escapable>(
|
||||
copying items: borrowing S
|
||||
) throws(E) {
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
@@ -478,12 +478,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items`, as amortized
|
||||
/// over many similar invocations on the same deque.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<
|
||||
S: Iterable_<Element, Never> & Sequence<Element>
|
||||
>(
|
||||
public mutating func prepend<S: Iterable_ & Sequence<Element>>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
self._prepend(copying: items)
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._prepend(copying: items)
|
||||
}
|
||||
|
||||
/// Copies the elements of a borrowing sequence to the end of this deque.
|
||||
@@ -497,12 +496,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
|
||||
/// - Complexity: O(*m*), where *m* is the length of `items` when amortized
|
||||
/// over many similar invocations on the same deque.
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func prepend<
|
||||
S: Iterable_<Element, Never> & Collection<Element>
|
||||
>(
|
||||
public mutating func prepend<S: Iterable_ & Collection<Element>>(
|
||||
copying items: borrowing S
|
||||
) {
|
||||
self._prepend(copying: items, exactCount: items.count)
|
||||
) throws(S.Failure_)
|
||||
where S.Element_ == Element {
|
||||
try self._prepend(copying: items, exactCount: items.count)
|
||||
}
|
||||
|
||||
/// Copies the elements of a container to the end of this deque.
|
||||
|
||||
Reference in new issue
Block a user