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
@@ -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