mirror of
https://github.com/apple/swift-collections
synced 2026-11-23 04:24:23 +00:00
42 lines
1.3 KiB
Swift
42 lines
1.3 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// 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
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if !COLLECTIONS_SINGLE_MODULE
|
|
import InternalCollectionsUtilities
|
|
#endif
|
|
|
|
#if compiler(>=6.4) && UnstableContainersPreview
|
|
|
|
@available(SwiftStdlib 5.0, *)
|
|
extension Iterable_ where Self: ~Copyable & ~Escapable, Element_: Copyable {
|
|
@inlinable
|
|
package func _copyContents(
|
|
intoPrefixOf buffer: UnsafeMutableBufferPointer<Element_>
|
|
) throws(Failure_) -> Int {
|
|
var target = buffer
|
|
var it = self.makeIterableIterator_()
|
|
while target.count != 0 {
|
|
let span = try it.nextSpan_(maximumCount: target.count)
|
|
if span.isEmpty {
|
|
return buffer.count - target.count
|
|
}
|
|
target._initializeAndDropPrefix(copying: span)
|
|
}
|
|
let test = try it.nextSpan_()
|
|
precondition(test.isEmpty, "Contents do not fit in target buffer")
|
|
return buffer.count
|
|
}
|
|
}
|
|
|
|
#endif
|