mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +00:00
Merge pull request #570 from lorentey/remove-outputspan-workaround
Remove workaround for bug in OutputSpan.wUMBP
This commit is contained in:
13 files changed
+27
-62
No files matched your search
@@ -41,7 +41,7 @@ extension OutputSpan where Element: ~Copyable {
|
||||
@inlinable
|
||||
package mutating func _popLast() -> Element? {
|
||||
// FIXME: This needs to be in the stdlib.
|
||||
_withUnsafeMutableBufferPointer { buffer, count in
|
||||
withUnsafeMutableBufferPointer { buffer, count in
|
||||
guard count > 0 else { return nil }
|
||||
count &-= 1
|
||||
return buffer.moveElement(from: count)
|
||||
@@ -59,7 +59,7 @@ extension OutputSpan where Element: ~Copyable {
|
||||
) {
|
||||
// FIXME: This needs to be in the stdlib.
|
||||
guard source.count > 0 else { return }
|
||||
self._withUnsafeMutableBufferPointer { dst, dstCount in
|
||||
self.withUnsafeMutableBufferPointer { dst, dstCount in
|
||||
let dstEnd = dstCount + source.count
|
||||
precondition(dstEnd <= dst.count, "OutputSpan capacity overflow")
|
||||
dst
|
||||
@@ -92,7 +92,7 @@ extension OutputSpan where Element: ~Copyable {
|
||||
@_lifetime(self: copy self)
|
||||
package mutating func _append(moving source: inout OutputSpan<Element>) {
|
||||
// FIXME: This needs to be in the stdlib.
|
||||
source._withUnsafeMutableBufferPointer { src, srcCount in
|
||||
source.withUnsafeMutableBufferPointer { src, srcCount in
|
||||
let items = src._extracting(uncheckedFrom: 0, to: srcCount)
|
||||
self._append(moving: items)
|
||||
srcCount = 0
|
||||
@@ -106,7 +106,7 @@ extension OutputSpan /*where Element: Copyable*/ {
|
||||
@_lifetime(self: copy self)
|
||||
package mutating func _append(copying source: UnsafeBufferPointer<Element>) {
|
||||
// FIXME: This needs to be in the stdlib.
|
||||
self._withUnsafeMutableBufferPointer { dst, dstCount in
|
||||
self.withUnsafeMutableBufferPointer { dst, dstCount in
|
||||
let dstEnd = dstCount + source.count
|
||||
precondition(dstEnd <= dst.count, "OutputSpan capacity overflow")
|
||||
dst
|
||||
@@ -126,39 +126,4 @@ extension OutputSpan /*where Element: Copyable*/ {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@inlinable // FIXME: This should be implied by @_aeic
|
||||
@_lifetime(self: copy self)
|
||||
package mutating func _withUnsafeMutableBufferPointer<E: Error, R: ~Copyable>(
|
||||
_ body: (
|
||||
UnsafeMutableBufferPointer<Element>,
|
||||
_ initializedCount: inout Int
|
||||
) throws(E) -> R
|
||||
) throws(E) -> R {
|
||||
// FIXME: Work around https://github.com/apple/swift-collections/issues/561 / rdar://169036911
|
||||
let capacity = self.capacity
|
||||
let r = try self.withUnsafeMutableBufferPointer { buffer, initializedCount throws(E) -> R? in
|
||||
if buffer.count == capacity {
|
||||
return try body(buffer, &initializedCount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if let r { return r }
|
||||
|
||||
let start = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow.
|
||||
let correctedBuffer = UnsafeMutableRawBufferPointer(
|
||||
start: .init(mutating: start), // Wow, wow.
|
||||
count: self.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -146,7 +146,7 @@ where Self: ~Copyable & ~Escapable, Element: Copyable
|
||||
@_lifetime(self: copy self)
|
||||
@_transparent
|
||||
public mutating func copyContents(into target: inout OutputSpan<Element>) {
|
||||
target._withUnsafeMutableBufferPointer { dst, dstCount in
|
||||
target.withUnsafeMutableBufferPointer { dst, dstCount in
|
||||
var tail = dst._extracting(droppingFirst: dstCount)
|
||||
while !tail.isEmpty {
|
||||
let src = nextSpan(maximumCount: tail.count)
|
||||
|
||||
Reference in new issue
Block a user