mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
Add temporary workaround for broken OutputSpan.wUMBP in current toolchain snapshots
(cherry picked from commit 0b1ff87d6773fe568945d8af86a236dbbf9157d9)
This commit is contained in:
1 parent
ead06d8983
commit
942cfbfd68
1 file changed
+25
@@ -250,6 +250,31 @@ extension RigidArray where Element: ~Copyable {
|
||||
#endif
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@_lifetime(self: copy self)
|
||||
mutating func _withUnsafeMutableBufferPointer<E: Error, R: ~Copyable>(
|
||||
_ body: (
|
||||
UnsafeMutableBufferPointer<Element>,
|
||||
_ initializedCount: inout Int
|
||||
) throws(E) -> R
|
||||
) throws(E) -> R {
|
||||
// FIXME: Work around rdar://169036911
|
||||
let capacity = self.capacity
|
||||
let baseAddress = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow.
|
||||
return try withUnsafeMutableBufferPointer { buffer, count throws(E) in
|
||||
let correctedBuffer = UnsafeMutableRawBufferPointer(
|
||||
start: .init(mutating: baseAddress), // Wow, wow.
|
||||
count: capacity &* MemoryLayout<Element>.stride)
|
||||
return try correctedBuffer.withMemoryRebound(to: Element.self) {
|
||||
correctBuffer throws(E) in
|
||||
try body(correctBuffer, &count)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray {
|
||||
/// Copies the elements of a fully initialized buffer pointer into this
|
||||
|
||||
Reference in new issue
Block a user