Эх сурвалжийг харах

It's faster with Collection than with Sequence

Marcin Krzyżanowski 8 жил өмнө
parent
commit
f108960fcf

+ 2 - 2
Sources/CryptoSwift/AES.swift

@@ -434,7 +434,7 @@ extension AES {
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
         }
         }
 
 
-        mutating public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+        mutating public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
             self.accumulated += bytes
             self.accumulated += bytes
 
 
             if isLast {
             if isLast {
@@ -484,7 +484,7 @@ extension AES {
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
             self.paddingRequired = aes.blockMode.options.contains(.PaddingRequired)
         }
         }
 
 
-        mutating public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+        mutating public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
             // prepend "offset" number of bytes at the begining
             // prepend "offset" number of bytes at the begining
             if self.offset > 0 {
             if self.offset > 0 {
                 self.accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes
                 self.accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes

+ 2 - 2
Sources/CryptoSwift/ChaCha20.swift

@@ -162,7 +162,7 @@ extension ChaCha20 {
             self.chacha = chacha
             self.chacha = chacha
         }
         }
 
 
-        mutating public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+        mutating public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
             self.accumulated += bytes
             self.accumulated += bytes
 
 
             var encrypted = Array<UInt8>()
             var encrypted = Array<UInt8>()
@@ -192,7 +192,7 @@ extension ChaCha20 {
             self.chacha = chacha
             self.chacha = chacha
         }
         }
 
 
-        mutating public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = true) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+        mutating public func update<T: Collection>(withBytes bytes: T, isLast: Bool = true) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
             // prepend "offset" number of bytes at the begining
             // prepend "offset" number of bytes at the begining
             if self.offset > 0 {
             if self.offset > 0 {
                 self.accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes
                 self.accumulated += Array<UInt8>(repeating: 0, count: offset) + bytes

+ 1 - 1
Sources/CryptoSwift/MD5.swift

@@ -106,7 +106,7 @@ public final class MD5: DigestType {
 
 
 extension MD5: Updatable {
 extension MD5: Updatable {
 
 
-    public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+    public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
         self.accumulated += bytes
         self.accumulated += bytes
 
 
         if isLast {
         if isLast {

+ 1 - 1
Sources/CryptoSwift/SHA1.swift

@@ -92,7 +92,7 @@ public final class SHA1: DigestType {
 
 
 extension SHA1: Updatable {
 extension SHA1: Updatable {
 
 
-    public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+    public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
         self.accumulated += bytes
         self.accumulated += bytes
 
 
         if isLast {
         if isLast {

+ 1 - 1
Sources/CryptoSwift/SHA2.swift

@@ -258,7 +258,7 @@ public final class SHA2: DigestType {
 
 
 extension SHA2: Updatable {
 extension SHA2: Updatable {
 
 
-    public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+    public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
         self.accumulated += bytes
         self.accumulated += bytes
 
 
         if isLast {
         if isLast {

+ 1 - 1
Sources/CryptoSwift/SHA3.swift

@@ -238,7 +238,7 @@ public final class SHA3: DigestType {
 
 
 extension SHA3: Updatable {
 extension SHA3: Updatable {
 
 
-    public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+    public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
         self.accumulated += bytes
         self.accumulated += bytes
 
 
         if isLast {
         if isLast {

+ 7 - 7
Sources/CryptoSwift/Updatable.swift

@@ -16,7 +16,7 @@ public protocol Updatable {
     /// - parameter bytes: Bytes to process
     /// - parameter bytes: Bytes to process
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - returns: Processed data or empty array.
     /// - returns: Processed data or empty array.
-    mutating func update<T: Sequence>(withBytes bytes: T, isLast: Bool) throws -> Array<UInt8> where T.Iterator.Element == UInt8
+    mutating func update<T: Collection>(withBytes bytes: T, isLast: Bool) throws -> Array<UInt8> where T.Iterator.Element == UInt8
 
 
     /// Update given bytes in chunks.
     /// Update given bytes in chunks.
     ///
     ///
@@ -24,30 +24,30 @@ public protocol Updatable {
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter isLast: (Optional) Given chunk is the last one. No more updates after this call.
     /// - parameter output: Resulting data
     /// - parameter output: Resulting data
     /// - returns: Processed data or empty array.
     /// - returns: Processed data or empty array.
-    mutating func update<T: Sequence>(withBytes bytes: T, isLast: Bool, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8
+    mutating func update<T: Collection>(withBytes bytes: T, isLast: Bool, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8
 
 
     /// Finish updates. This may apply padding.
     /// Finish updates. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - parameter bytes: Bytes to process
     /// - returns: Processed data.
     /// - returns: Processed data.
-    mutating func finish<T: Sequence>(withBytes bytes: T) throws -> Array<UInt8> where T.Iterator.Element == UInt8
+    mutating func finish<T: Collection>(withBytes bytes: T) throws -> Array<UInt8> where T.Iterator.Element == UInt8
 
 
     /// Finish updates. This may apply padding.
     /// Finish updates. This may apply padding.
     /// - parameter bytes: Bytes to process
     /// - parameter bytes: Bytes to process
     /// - parameter output: Resulting data
     /// - parameter output: Resulting data
     /// - returns: Processed data.
     /// - returns: Processed data.
-    mutating func finish<T: Sequence>(withBytes bytes: T, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8
+    mutating func finish<T: Collection>(withBytes bytes: T, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8
 }
 }
 
 
 extension Updatable {
 extension Updatable {
 
 
-    mutating public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8 {
+    mutating public func update<T: Collection>(withBytes bytes: T, isLast: Bool = false, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8 {
         let processed = try self.update(withBytes: bytes, isLast: isLast)
         let processed = try self.update(withBytes: bytes, isLast: isLast)
         if (!processed.isEmpty) {
         if (!processed.isEmpty) {
             output(processed)
             output(processed)
         }
         }
     }
     }
 
 
-    mutating public func finish<T: Sequence>(withBytes bytes: T) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+    mutating public func finish<T: Collection>(withBytes bytes: T) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
         return try self.update(withBytes: bytes, isLast: true)
         return try self.update(withBytes: bytes, isLast: true)
     }
     }
 
 
@@ -55,7 +55,7 @@ extension Updatable {
         return try self.update(withBytes: [], isLast: true)
         return try self.update(withBytes: [], isLast: true)
     }
     }
 
 
-    mutating public func finish<T: Sequence>(withBytes bytes: T, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8 {
+    mutating public func finish<T: Collection>(withBytes bytes: T, output: (Array<UInt8>) -> Void) throws where T.Iterator.Element == UInt8 {
         let processed = try self.update(withBytes: bytes, isLast: true)
         let processed = try self.update(withBytes: bytes, isLast: true)
         if (!processed.isEmpty) {
         if (!processed.isEmpty) {
             output(processed)
             output(processed)