From 1c840e63da691fade306bea2429c3d29865e802b Mon Sep 17 00:00:00 2001 From: AZero13 Date: Sat, 6 Dec 2025 12:41:27 -0500 Subject: [PATCH 1/2] first should get the Initialized elements --- Sources/ContainersPreview/InputSpan.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/ContainersPreview/InputSpan.swift b/Sources/ContainersPreview/InputSpan.swift index 63e7dbc8..a791de3a 100644 --- a/Sources/ContainersPreview/InputSpan.swift +++ b/Sources/ContainersPreview/InputSpan.swift @@ -64,7 +64,9 @@ extension InputSpan where Element: ~Copyable { @unsafe internal func _first() -> UnsafeMutableRawPointer { // NOTE: `_pointer` must be known to be not-nil. - unsafe _start().advanced(by: _count &* MemoryLayout.stride) + // Initialized elements live at the end of the buffer; skip the uninitialized prefix. + let offset = (capacity &- _count) &* MemoryLayout.stride + unsafe _start().advanced(by: offset) } @unsafe From ad176827391e97cc1a919f38f3f6af655184facb Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 9 Dec 2025 11:21:18 -0800 Subject: [PATCH 2/2] Update Sources/ContainersPreview/InputSpan.swift --- Sources/ContainersPreview/InputSpan.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/ContainersPreview/InputSpan.swift b/Sources/ContainersPreview/InputSpan.swift index a791de3a..7560041c 100644 --- a/Sources/ContainersPreview/InputSpan.swift +++ b/Sources/ContainersPreview/InputSpan.swift @@ -64,9 +64,8 @@ extension InputSpan where Element: ~Copyable { @unsafe internal func _first() -> UnsafeMutableRawPointer { // NOTE: `_pointer` must be known to be not-nil. - // Initialized elements live at the end of the buffer; skip the uninitialized prefix. let offset = (capacity &- _count) &* MemoryLayout.stride - unsafe _start().advanced(by: offset) + return unsafe _start().advanced(by: offset) } @unsafe