Avatar
norio_nomura 3/8/2018 3:50 AM
syncなしはこうなった。 extension Array { func concurrentMap<B>(_ transform: (Element) -> B) -> [B] { var result = ContiguousArray<B?>(repeating: nil, count: count) return result.withUnsafeMutableBufferPointer { buffer in DispatchQueue.concurrentPerform(iterations: buffer.count) { idx in buffer[idx] = transform(self[idx]) } return buffer.map { $0! } } } }