File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -315,6 +315,7 @@ extension OutputSpan where Element: ~Copyable {
315315 @_alwaysEmitIntoClient
316316 @lifetime ( self : copy self )
317317 public mutating func removeAll( ) {
318+ guard count > 0 else { return }
318319 _ = unsafe _start( ) . withMemoryRebound ( to: Element . self, capacity: _count) {
319320 unsafe $0. deinitialize ( count: _count)
320321 }
Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ struct Allocation<T>: ~Copyable {
3535 _ body: ( inout OutputSpan < T > ) throws ( E ) -> Void
3636 ) throws ( E) {
3737 if count != nil { fatalError ( ) }
38- var outputBuffer = OutputSpan < T > ( buffer: allocation, initializedCount: 0 )
38+ var allocation = allocation
39+ if allocation. count == 0 { allocation = . init( start: nil , count: 0 ) }
40+ var outputBuffer = OutputSpan ( buffer: allocation, initializedCount: 0 )
3941 do {
4042 try body ( & outputBuffer)
4143 let initialized = outputBuffer. finalize ( for: allocation)
@@ -188,6 +190,20 @@ suite.test("deinitialize buffer")
188190 catch {
189191 expectTrue ( false )
190192 }
193+
194+ a = Allocation ( of: 0 , Int . self)
195+ do {
196+ try a. initialize {
197+ expectEqual ( $0. freeCapacity, 0 )
198+ throw MyTestError . error
199+ }
200+ }
201+ catch MyTestError . error {
202+ expectEqual ( a. isEmpty, true )
203+ }
204+ catch {
205+ expectTrue ( false )
206+ }
191207}
192208
193209suite. test ( " InlineArray initialization " )
You can’t perform that action at this time.
0 commit comments