Use Iterable from the Standard Library, replacing the local definition

This commit is contained in:
Karoy Lorentey committed 2026-07-27 13:32:46 -07:00
1 parent 0afc8e0e16
commit 669eb09cea
68 files changed
+565 -921

No files matched your search

@@ -256,11 +256,11 @@ extension RigidArray {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _append<
Source: Iterable_ & ~Copyable & ~Escapable
Source: Iterable & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
let target = _freeSpace
_count += try newElements._copyContents(intoPrefixOf: target)
}
@@ -280,11 +280,11 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable_ & ~Copyable & ~Escapable
Source: Iterable & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
try _append(copying: newElements)
}
#endif
@@ -324,11 +324,11 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable_ & Sequence<Element>
Source: Iterable & Sequence<Element>
>(
copying newElements: Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
try _append(copying: newElements)
}
#endif
@@ -20,16 +20,13 @@ import ContainersPreview
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension RigidArray: Iterable_ where Element: ~Copyable {
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
extension RigidArray: Iterable where Element: ~Copyable {
public typealias BorrowingIterator = Span<Element>.BorrowingIterator
@_alwaysEmitIntoClient
@inline(__always)
public func makeBorrowingIterator_() -> BorrowingIterator_ {
let span = self.span
let it = span.makeBorrowingIterator_()
// FIXME: `it` is borrowing `span`, not self
return _overrideLifetime(it, borrowing: self)
public func makeBorrowingIterator() -> BorrowingIterator {
self.span._makeBorrowingIterator(from: 0, to: count)
}
}
#endif
@@ -41,17 +38,14 @@ extension RigidArray: Container where Element: ~Copyable {
@_lifetime(borrow self)
public func makeBorrowingIterator(
from start: Index, to end: Index
) -> BorrowingIterator_ {
) -> BorrowingIterator {
// FIXME: `makeBorrowingIterator` would be borrowing the temporary `span`, not self
self.span._makeBorrowingIterator(from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
precondition(
iterator._span.isTriviallyIdentical(to: self.span),
"Invalid iterator instance")
return iterator._start
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
self.span.currentIndex(of: &iterator)
}
}
@@ -73,7 +67,7 @@ extension RigidArray: RangeReplaceableContainer where Element: ~Copyable {}
@available(SwiftStdlib 5.0, *)
extension RigidArray where Element: ~Copyable {
@inlinable
public var underestimatedCount_: Int { count }
public var underestimatedCount: Int { count }
/// A Boolean value indicating whether this array contains no elements.
///
@@ -128,11 +128,11 @@ extension RigidArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable_ & ~Copyable & ~Escapable>(
public init<Source: Iterable & ~Copyable & ~Escapable>(
capacity: Int,
copying contents: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
self.init(capacity: capacity)
try self.append(copying: contents)
}
@@ -151,11 +151,11 @@ extension RigidArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable_ & Sequence<Element>>(
public init<Source: Iterable & Sequence<Element>>(
capacity: Int,
copying contents: Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
self.init(capacity: capacity)
try self.append(copying: contents)
}
@@ -592,17 +592,17 @@ extension RigidArray {
copyingContainer items: borrowing C,
newCount: Int
) {
var it = items.makeBorrowingIterator_()
var it = items.makeBorrowingIterator()
self.replace(removing: subrange, addingCount: newCount) { target in
while !target.isFull {
let source = it.nextSpan_(maxCount: target.freeCapacity)
let source = it.nextSpan(maxCount: target.freeCapacity)
precondition(
!source.isEmpty,
"Broken Container: count doesn't match contents")
target._append(copying: source)
}
precondition(
it.nextSpan_().isEmpty,
it.nextSpan().isEmpty,
"Broken Container: count doesn't match contents")
}
}