Iterable → BorrowingSequence, BorrowIterator → BorrowingIterator

This commit is contained in:
Karoy Lorentey committed 2026-01-25 16:42:37 -08:00
1 parent fabe5d8c87
commit e4aba4c1c9
24 files changed
+287 -187

No files matched your search

+10 -10
View File
@@ -274,9 +274,9 @@ extension RigidArray {
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@inlinable
internal mutating func _append<
Source: Iterable<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence<Element> & ~Copyable & ~Escapable
>(
copyingIterable newElements: borrowing Source
copying newElements: borrowing Source
) {
let target = _freeSpace
_count += newElements._copyContents(intoPrefixOf: target)
@@ -284,10 +284,10 @@ extension RigidArray {
#endif
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Copies the elements of a container to the end of this array.
/// Copies the elements of a borrowing sequence to the end of this array.
///
/// If the array does not have sufficient capacity to hold all items in the
/// source iterable, then this triggers a runtime error.
/// source sequence, then this triggers a runtime error.
///
/// - Parameters
/// - newElements: A container whose contents to copy into the array.
@@ -296,11 +296,11 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence<Element> & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) {
_append(copyingIterable: newElements)
_append(copying: newElements)
}
#endif
@@ -326,10 +326,10 @@ extension RigidArray {
}
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Copies the elements of a container to the end of this array.
/// Copies the elements of a borrowing sequence to the end of this array.
///
/// If the array does not have sufficient capacity to hold all items in the
/// source iterable, then this triggers a runtime error.
/// source sequence, then this triggers a runtime error.
///
/// - Parameters
/// - newElements: The new elements to copy into the array.
@@ -338,9 +338,9 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable<Element> & Sequence<Element>
Source: BorrowingSequence<Element> & Sequence<Element>
>(copying newElements: Source) {
_append(copyingIterable: newElements)
_append(copying: newElements)
}
#endif
}
@@ -2,7 +2,7 @@
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
// Copyright (c) 2024 - 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
@@ -98,7 +98,7 @@ extension RigidArray /*where Element: Copyable*/ {
/// The container must not contain more than `capacity` elements.
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable<Element> & ~Copyable & ~Escapable>(
public init<Source: BorrowingSequence<Element> & ~Copyable & ~Escapable>(
capacity: Int,
copying contents: borrowing Source
) {
@@ -119,7 +119,7 @@ extension RigidArray /*where Element: Copyable*/ {
/// The container must not contain more than `capacity` elements.
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable<Element> & Sequence<Element>>(
public init<Source: BorrowingSequence<Element> & Sequence<Element>>(
capacity: Int,
copying contents: Source
) {
+3 -3
View File
@@ -286,9 +286,9 @@ extension RigidArray where Element: ~Copyable {
#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 5.0, *)
extension RigidArray: Iterable where Element: ~Copyable {
extension RigidArray: BorrowingSequence where Element: ~Copyable {
@frozen
public struct BorrowIterator: ~Copyable, ~Escapable, BorrowIteratorProtocol {
public struct BorrowingIterator: ~Copyable, ~Escapable, BorrowingIteratorProtocol {
@usableFromInline
internal let _span: Span<Element>
@@ -327,7 +327,7 @@ extension RigidArray: Iterable where Element: ~Copyable {
@_alwaysEmitIntoClient
@inline(__always)
public func startBorrowIteration() -> BorrowIterator {
public func makeBorrowingIterator() -> BorrowingIterator {
.init(_span: self.span, offset: 0)
}
}
@@ -2,7 +2,7 @@
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
// Copyright (c) 2024 - 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
@@ -233,12 +233,12 @@ extension UniqueArray {
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@inlinable
internal mutating func _append<
Source: Iterable<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence<Element> & ~Copyable & ~Escapable
>(
copyingIterable newElements: borrowing Source
copying newElements: borrowing Source
) {
_ensureFreeCapacity(newElements.underestimatedCount)
var it = newElements.startBorrowIteration()
var it = newElements.makeBorrowingIterator()
while true {
let span = it.nextSpan()
if span.isEmpty { break }
@@ -250,7 +250,7 @@ extension UniqueArray {
#endif
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Copies the elements of an iterable to the end of this array.
/// Copies the elements of a borrowing sequence to the end of this array.
///
/// If the array does not have sufficient capacity to hold enough elements,
/// then this reallocates the array's storage to extend its capacity, using
@@ -266,11 +266,11 @@ extension UniqueArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence<Element> & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) {
self._append(copyingIterable: newElements)
self._append(copying: newElements)
}
#endif
@@ -320,9 +320,9 @@ extension UniqueArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable<Element> & Sequence<Element>
Source: BorrowingSequence<Element> & Sequence<Element>
>(copying newElements: Source) {
self._append(copyingIterable: newElements)
self._append(copying: newElements)
}
#endif
}
@@ -2,7 +2,7 @@
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
// Copyright (c) 2024 - 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
@@ -70,16 +70,16 @@ extension UniqueArray where Element: ~Copyable {
extension UniqueArray /*where Element: Copyable*/ {
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
/// Creates a new array with the specified initial capacity, holding a copy
/// of the contents of a given iterable.
/// of the contents of a given borrowing sequence.
///
/// - Parameters:
/// - capacity: The storage capacity of the new array, or nil to allocate
/// just enough capacity to store the contents.
/// - contents: An iterable whose contents to copy into the new array.
/// The iterable must not contain more than `capacity` elements.
/// - contents: A sequence whose contents to copy into the new array.
/// The sequence must not contain more than `capacity` elements.
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable<Element> & ~Copyable & ~Escapable>(
public init<Source: BorrowingSequence<Element> & ~Copyable & ~Escapable>(
capacity: Int? = nil,
copying contents: borrowing Source
) {
@@ -115,7 +115,7 @@ extension UniqueArray /*where Element: Copyable*/ {
/// - contents: The container whose contents to copy into the new array.
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable<Element> & Sequence<Element>>(
public init<Source: BorrowingSequence<Element> & Sequence<Element>>(
capacity: Int? = nil,
copying contents: Source
) {
+5 -5
View File
@@ -2,7 +2,7 @@
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
// Copyright (c) 2024 - 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
@@ -177,8 +177,8 @@ extension UniqueArray where Element: ~Copyable {
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 5.0, *)
extension UniqueArray: Iterable where Element: ~Copyable {
public typealias BorrowIterator = RigidArray<Element>.BorrowIterator
extension UniqueArray: BorrowingSequence where Element: ~Copyable {
public typealias BorrowingIterator = RigidArray<Element>.BorrowingIterator
public var estimatedCount: ContainersPreview.EstimatedCount {
.exactly(count)
@@ -186,8 +186,8 @@ extension UniqueArray: Iterable where Element: ~Copyable {
@_alwaysEmitIntoClient
@inline(__always)
public func startBorrowIteration() -> BorrowIterator {
self._storage.startBorrowIteration()
public func makeBorrowingIterator() -> BorrowingIterator {
self._storage.makeBorrowingIterator()
}
}
#endif