2 // Collection+OAuthSwift.swift
5 // Created by phimage on 02/10/16.
6 // Copyright © 2016 Dongri Jin. All rights reserved.
11 extension Collection where Self.Iterator.Element == UInt8, Self.Index == Int {
13 var toUInt32: UInt32 {
14 assert(self.count > 3)
15 // XXX optimize do the job only for the first one...
16 return toUInt32Array()[0]
19 func toUInt32Array() -> [UInt32] {
20 var result = [UInt32]()
21 result.reserveCapacity(16)
22 for idx in stride(from: self.startIndex, to: self.endIndex, by: MemoryLayout<UInt32>.size) {
24 val |= self.count > 3 ? UInt32(self[idx.advanced(by: 3)]) << 24 : 0
25 val |= self.count > 2 ? UInt32(self[idx.advanced(by: 2)]) << 16 : 0
26 val |= self.count > 1 ? UInt32(self[idx.advanced(by: 1)]) << 8 : 0
27 //swiftlint:disable:next empty_count
28 val |= self.count > 0 ? UInt32(self[idx]) : 0