mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
rearrange horribleness to insert preconditions
(cherry picked from commit 085fc446b1bf449c5eedf4754bcc5f17c5fe7c42)
This commit is contained in:
1 parent
bcbee23816
commit
1fe2fb03a8
1 file changed
+8
-9
@@ -261,15 +261,14 @@ extension OutputSpan where Element: ~Copyable {
|
||||
) 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)
|
||||
let correctedBuffer = UnsafeMutableRawBufferPointer(
|
||||
start: .init(mutating: span.withUnsafeBufferPointer { $0.baseAddress }), // Wow, wow.
|
||||
count: capacity &* MemoryLayout<Element>.stride)
|
||||
return try correctedBuffer.withMemoryRebound(to: Element.self) { correctBuffer throws(E) in
|
||||
precondition(correctBuffer.count == self.capacity)
|
||||
return try self.withUnsafeMutableBufferPointer { badBuffer, count throws(E) in
|
||||
precondition(badBuffer.baseAddress == correctBuffer.baseAddress)
|
||||
return try body(correctBuffer, &count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user