diff --git a/Sources/Future/MutableSpan.swift b/Sources/Future/MutableSpan.swift index 52e34609..10bf47d6 100644 --- a/Sources/Future/MutableSpan.swift +++ b/Sources/Future/MutableSpan.swift @@ -80,7 +80,7 @@ extension MutableSpan { @_disallowFeatureSuppression(NonescapableTypes) @_alwaysEmitIntoClient - internal init( + public init( _unsafeElements elements: Slice> ) -> dependsOn(immortal) Self { self.init(_unsafeElements: UnsafeMutableBufferPointer(rebasing: elements)) @@ -90,29 +90,16 @@ extension MutableSpan { @_disallowFeatureSuppression(NonescapableTypes) extension MutableSpan where Element: BitwiseCopyable { - @_disallowFeatureSuppression(NonescapableTypes) - @_alwaysEmitIntoClient - public init( - _unsafeElements buffer: UnsafeMutableBufferPointer - ) -> dependsOn(immortal) Self { - self.init(_unchecked: buffer) - } - - @_disallowFeatureSuppression(NonescapableTypes) - @_alwaysEmitIntoClient - public init( - _unsafeStart start: UnsafeMutablePointer, - count: Int - ) -> dependsOn(immortal) Self { - precondition(count >= 0, "Count must not be negative") - self.init(_unchecked: start, count: count) - } - @_disallowFeatureSuppression(NonescapableTypes) @_alwaysEmitIntoClient public init( _unsafeBytes buffer: UnsafeMutableRawBufferPointer ) -> dependsOn(immortal) Self { + precondition( + ((Int(bitPattern: buffer.baseAddress) & + (MemoryLayout.alignment&-1)) == 0), + "baseAddress must be properly aligned to access Element" + ) let (byteCount, stride) = (buffer.count, MemoryLayout.stride) let (count, remainder) = byteCount.quotientAndRemainder(dividingBy: stride) precondition(remainder == 0, "Span must contain a whole number of elements") @@ -126,23 +113,12 @@ extension MutableSpan where Element: BitwiseCopyable { byteCount: Int ) -> dependsOn(immortal) Self { precondition(byteCount >= 0, "Count must not be negative") - let stride = MemoryLayout.stride - let (count, remainder) = byteCount.quotientAndRemainder(dividingBy: stride) - precondition(remainder == 0, "Span must contain a whole number of elements") - self.init(_unchecked: pointer, count: count) + self.init(_unsafeBytes: .init(start: pointer, count: byteCount)) } @_disallowFeatureSuppression(NonescapableTypes) @_alwaysEmitIntoClient - internal init( - _unsafeElements elements: Slice> - ) -> dependsOn(immortal) Self { - self.init(_unsafeElements: UnsafeMutableBufferPointer(rebasing: elements)) - } - - @_disallowFeatureSuppression(NonescapableTypes) - @_alwaysEmitIntoClient - internal init( + public init( _unsafeBytes buffer: Slice ) -> dependsOn(immortal) Self { self.init(_unsafeBytes: UnsafeMutableRawBufferPointer(rebasing: buffer))