Browse Source

Specialize hint for generic collections

Marcin Krzyżanowski 9 năm trước cách đây
mục cha
commit
99a397bcdf

+ 2 - 0
Sources/CryptoSwift/UInt16+Extension.swift

@@ -8,10 +8,12 @@
 
 /** array of bytes */
 extension UInt16 {
+    @_specialize(ArraySlice<UInt8>)
     init<T: Collection>(bytes: T) where T.Iterator.Element == UInt8, T.Index == Int {
         self = UInt16(bytes: bytes, fromIndex: bytes.startIndex)
     }
 
+    @_specialize(ArraySlice<UInt8>)
     init<T: Collection>(bytes: T, fromIndex index: T.Index) where T.Iterator.Element == UInt8, T.Index == Int {
         let val0 = UInt16(bytes[index.advanced(by: 0)]) << 8
         let val1 = UInt16(bytes[index.advanced(by: 1)])

+ 2 - 0
Sources/CryptoSwift/UInt32+Extension.swift

@@ -18,10 +18,12 @@ extension UInt32: _UInt32Type {}
 
 /** array of bytes */
 extension UInt32 {
+    @_specialize(ArraySlice<UInt8>)
     init<T: Collection>(bytes: T) where T.Iterator.Element == UInt8, T.Index == Int {
         self = UInt32(bytes: bytes, fromIndex: bytes.startIndex)
     }
 
+    @_specialize(ArraySlice<UInt8>)
     init<T: Collection>(bytes: T, fromIndex index: T.Index) where T.Iterator.Element == UInt8, T.Index == Int {
         let val0 = UInt32(bytes[index.advanced(by: 0)]) << 24
         let val1 = UInt32(bytes[index.advanced(by: 1)]) << 16

+ 2 - 0
Sources/CryptoSwift/UInt64+Extension.swift

@@ -8,10 +8,12 @@
 
 /** array of bytes */
 extension UInt64 {
+    @_specialize(ArraySlice<UInt8>)
     init<T: Collection>(bytes: T) where T.Iterator.Element == UInt8, T.Index == Int {
         self = UInt64(bytes: bytes, fromIndex: bytes.startIndex)
     }
 
+    @_specialize(ArraySlice<UInt8>)
     init<T: Collection>(bytes: T, fromIndex index: T.Index) where T.Iterator.Element == UInt8, T.Index == Int {
         let val0 = UInt64(bytes[index.advanced(by: 0)]) << 56
         let val1 = UInt64(bytes[index.advanced(by: 1)]) << 48