Browse Source

rewrite these C-style for loops by hand

Evan Maloney 10 years ago
parent
commit
d0cbf98e26
2 changed files with 6 additions and 2 deletions
  1. 2 1
      Sources/CryptoSwift/Array+Extension.swift
  2. 4 1
      Sources/CryptoSwift/Rabbit.swift

+ 2 - 1
Sources/CryptoSwift/Array+Extension.swift

@@ -12,9 +12,10 @@ extension Array {
     func chunks(chunksize:Int) -> [Array<Element>] {
         var words = [[Element]]()
         words.reserveCapacity(self.count / chunksize)        
-        for var idx = chunksize; idx <= self.count; idx = idx + chunksize {
+        for var idx in chunksize ... self.count {
             let word = Array(self[idx - chunksize..<idx]) // this is slow for large table
             words.append(word)
+            idx = idx + chunksize
         }
         let reminder = Array(self.suffix(self.count % chunksize))
         if (reminder.count > 0) {

+ 4 - 1
Sources/CryptoSwift/Rabbit.swift

@@ -176,13 +176,16 @@ final public class Rabbit {
         
         var result = [UInt8](count: bytes.count, repeatedValue: 0)
         var output = nextOutput()
-        for var byteIdx = 0, outputIdx = 0; byteIdx < bytes.count; byteIdx += 1, outputIdx += 1 {
+        var outputIdx = 0
+        for byteIdx in 0 ..< bytes.count {
             if (outputIdx == Rabbit.blockSize) {
                 output = nextOutput()
                 outputIdx = 0
             }
             
             result[byteIdx] = bytes[byteIdx] ^ output[outputIdx]
+
+            outputIdx += 1
         }
         return result
     }