From 4ff4e75436935834b67a5f16833fd0501d37fe3e Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Wed, 14 Oct 2026 17:19:13 -0700 Subject: [PATCH] Fix implementation of `removeAll()` --- Sources/SpanPreview/InputSpan.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/SpanPreview/InputSpan.swift b/Sources/SpanPreview/InputSpan.swift index 68f16870..f989a27b 100644 --- a/Sources/SpanPreview/InputSpan.swift +++ b/Sources/SpanPreview/InputSpan.swift @@ -432,8 +432,10 @@ extension InputSpan where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(self: copy self) public mutating func removeAll() { - _ = unsafe _start().withMemoryRebound(to: Element.self, capacity: _count) { - unsafe $0.deinitialize(count: _count) + guard count > 0 else { return } + let start = unsafe _unsafeRawAddressOfSlot(uncheckedOffset: 0) + unsafe start.withMemoryRebound(to: Element.self, capacity: _count) { + _ = unsafe $0.deinitialize(count: _count) } _count = 0 }