File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,22 +9,40 @@ extension Data {
99
1010 @inline ( __always)
1111 func toU16( ) -> UInt16 {
12- return self . withUnsafeBytes { $0. bindMemory ( to: UInt16 . self) [ 0 ] }
12+ #if compiler(>=5.0)
13+ return self . withUnsafeBytes { $0. bindMemory ( to: UInt16 . self) [ 0 ] }
14+ #else
15+ return self . withUnsafeBytes { $0. pointee }
16+ #endif
1317 }
1418
1519 @inline ( __always)
1620 func toU32( ) -> UInt32 {
17- return self . withUnsafeBytes { $0. bindMemory ( to: UInt32 . self) [ 0 ] }
21+ #if compiler(>=5.0)
22+ return self . withUnsafeBytes { $0. bindMemory ( to: UInt32 . self) [ 0 ] }
23+ #else
24+ return self . withUnsafeBytes { $0. pointee }
25+ #endif
1826 }
1927
2028 @inline ( __always)
2129 func toU64( ) -> UInt64 {
22- return self . withUnsafeBytes { $0. bindMemory ( to: UInt64 . self) [ 0 ] }
30+ #if compiler(>=5.0)
31+ return self . withUnsafeBytes { $0. bindMemory ( to: UInt64 . self) [ 0 ] }
32+ #else
33+ return self . withUnsafeBytes { $0. pointee }
34+ #endif
2335 }
2436
2537 @inline ( __always)
2638 func toByteArray( _ count: Int ) -> [ UInt8 ] {
27- return self . withUnsafeBytes { $0. map { $0 } }
39+ #if compiler(>=5.0)
40+ return self . withUnsafeBytes { $0. map { $0 } }
41+ #else
42+ return self . withUnsafeBytes {
43+ [ UInt8] ( UnsafeBufferPointer ( start: $0, count: count) )
44+ }
45+ #endif
2846 }
2947
3048}
You can’t perform that action at this time.
0 commit comments