1717extension AsyncBufferSequence {
1818 /// A immutable collection of bytes
1919 public struct Buffer : Sendable {
20- #if os(Windows)
21- internal let data : [ UInt8 ]
22-
23- internal init ( data: [ UInt8 ] ) {
24- self . data = data
25- }
26-
27- internal static func createFrom( _ data: [ UInt8 ] ) -> [ Buffer ] {
28- return [ . init( data: data) ]
29- }
30- #else
31- // We need to keep the backingData alive while _ContiguousBufferView is alive
20+ #if canImport(Darwin)
21+ // We need to keep the backingData alive while Slice is alive
3222 internal let backingData : DispatchData
3323 internal let data : DispatchData . _ContiguousBufferView
3424
@@ -45,7 +35,17 @@ extension AsyncBufferSequence {
4535 }
4636 return slices. map { . init( data: $0, backingData: data) }
4737 }
48- #endif
38+ #else
39+ internal let data : [ UInt8 ]
40+
41+ internal init ( data: [ UInt8 ] ) {
42+ self . data = data
43+ }
44+
45+ internal static func createFrom( _ data: [ UInt8 ] ) -> [ Buffer ] {
46+ return [ . init( data: data) ]
47+ }
48+ #endif // canImport(Darwin)
4949 }
5050}
5151
@@ -92,26 +92,23 @@ extension AsyncBufferSequence.Buffer {
9292
9393// MARK: - Hashable, Equatable
9494extension AsyncBufferSequence . Buffer : Equatable , Hashable {
95- #if os(Windows)
96- // Compiler generated conformances
97- #else
95+ #if canImport(Darwin)
9896 public static func == ( lhs: AsyncBufferSequence . Buffer , rhs: AsyncBufferSequence . Buffer ) -> Bool {
99- return lhs. data. elementsEqual ( rhs. data)
97+ return lhs. data == rhs. data
10098 }
10199
102100 public func hash( into hasher: inout Hasher ) {
103- self . data. withUnsafeBytes { ptr in
104- hasher. combine ( bytes: ptr)
105- }
101+ hasher. combine ( self . data)
106102 }
107103 #endif
104+ // else Compiler generated conformances
108105}
109106
110107// MARK: - DispatchData.Block
111108#if canImport(Darwin) || canImport(Glibc) || canImport(Android) || canImport(Musl)
112109extension DispatchData {
113110 /// Unfortunately `DispatchData.Region` is not available on Linux, hence our own wrapper
114- internal struct _ContiguousBufferView : @unchecked Sendable , RandomAccessCollection {
111+ internal struct _ContiguousBufferView : @unchecked Sendable , RandomAccessCollection , Hashable {
115112 typealias Element = UInt8
116113
117114 internal let bytes : UnsafeBufferPointer < UInt8 >
@@ -127,6 +124,14 @@ extension DispatchData {
127124 return try body ( UnsafeRawBufferPointer ( self . bytes) )
128125 }
129126
127+ internal func hash( into hasher: inout Hasher ) {
128+ hasher. combine ( bytes: UnsafeRawBufferPointer ( self . bytes) )
129+ }
130+
131+ internal static func == ( lhs: DispatchData . _ContiguousBufferView , rhs: DispatchData . _ContiguousBufferView ) -> Bool {
132+ return lhs. bytes. elementsEqual ( rhs. bytes)
133+ }
134+
130135 subscript( position: Int ) -> UInt8 {
131136 _read {
132137 yield self . bytes [ position]
0 commit comments