[UInt32]를 [UInt8]으로 변환하는 함수의 현재 구현 속도를 높이려고합니다. [[UInt8]] 각 색인에 6 개의 배열이 있습니다.Swift에서 [UInt8] -> [UInt8] -> [[UInt8]] 전환
내 구현 :
extension Array {
func splitBy(subSize: Int) -> [[Element]] {
return 0.stride(to: self.count, by: subSize).map { startIndex in
let endIndex = startIndex.advancedBy(subSize, limit: self.count)
return Array(self[startIndex ..< endIndex])
}
}
}
func convertWordToBytes(fullW : [UInt32]) -> [[UInt8]] {
var combined8 = [UInt8]()
//Convert 17 [UInt32] to 68 [UInt8]
for i in 0...16{
_ = 24.stride(through: 0, by: -8).map {
combined8.append(UInt8(truncatingBitPattern: fullW[i] >> UInt32($0)))
}
}
//Split [UInt8] to [[UInt8]] with 6 values at each index.
let combined48 = combined8.splitBy(6)
return combined48
}
이 기능은 내 프로그램에 수백만 번 반복되며, 그 속도는 큰 부담이다.
누구나 아이디어가 있습니까? 감사합니다.
http://codereview.stackexchange.com – rmaddy
에 코드를 게시하는 것이 좋습니다. 코드가 Swift 2에 있습니다. Swift 2로 유지하거나 Swift 3으로 동시에 업데이트 하시겠습니까? –
이 컴퓨터는 너무 오래되었으므로 지금은 스위프트 2에 보관해야합니다. – p0ppy