mirror of
https://github.com/krzysztofzablocki/Sourcery.git
synced 2026-04-07 19:17:40 +00:00
cec7895f0a
* Adjusted file structure to accommodate two generated files * Adjusted scripting * Removed Description, Diffable, Equality for now * Removed Stencil import * Updated templates * Updated scripting * Updated generated coding * Disable build deletion (temp) * Updated template * Updated generated code * updated generated code * Updated generated code * Adjusted scripting * Updated scripting * Updated generated code * Reverted template deletion * Removed Stencil imports * Updated generated code * trigger CI * Removed description, diffable and equality stencil templates * Reverted temporary changes * Commented failing tests * Skipping JSExport for description & hash * Updated generated code * Enabled failing tests * Adding stencil templates back to test tests * Reset generated file for linux for test * Reverted Extensions for testing * Reverted ParserResultsComposed * Attempt to fix unit tests * Attempt to resolve unit test * Reverted TypeName asSource * Reverted TypeName revertion * Reverted revert of ParserResultComposed * Reverted revert of Extensions * Reverted revert of Linux.content.generated * Reverted attempts to fix unit tests * Fix for the failing codegen tests * Added clarifying comment * Removed description, diffable and equality stencil templates * Updated generated code * Tinkering with optimization level for speed boost * Excluded stencil templates for codegen * Fixed wrong compiler flag * Removed speed optimization to a separate PR * Reverted test code
33 lines
999 B
Swift
33 lines
999 B
Swift
//
|
|
// Created by Krzysztof Zablocki on 06/01/2017.
|
|
// Copyright (c) 2017 Pixle. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension Array {
|
|
func parallelFlatMap<T>(transform: (Element) -> [T]) -> [T] {
|
|
return parallelMap(transform: transform).flatMap { $0 }
|
|
}
|
|
|
|
func parallelCompactMap<T>(transform: (Element) -> T?) -> [T] {
|
|
return parallelMap(transform: transform).compactMap { $0 }
|
|
}
|
|
|
|
func parallelMap<T>(transform: (Element) -> T) -> [T] {
|
|
var result = ContiguousArray<T?>(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! }
|
|
}
|
|
}
|
|
|
|
func parallelPerform(transform: (Element) -> Void) {
|
|
DispatchQueue.concurrentPerform(iterations: count) { idx in
|
|
transform(self[idx])
|
|
}
|
|
}
|
|
}
|