Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 4cc21ff

Browse files
committed
Avoid soring elements
1 parent f544156 commit 4cc21ff

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

Sources/SwiftDoc/Extensions/Array+Parallel.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,23 @@ public extension RandomAccessCollection {
77
}
88

99
let indices = Array(self.indices)
10-
11-
var results = [(index: Index, result: Result<T, Error>)]()
12-
results.reserveCapacity(count)
10+
var results = [Result<T, Error>?](repeating: nil, count: count)
1311

1412
let queue = DispatchQueue(label: #function)
1513
DispatchQueue.concurrentPerform(iterations: count) { (iteration) in
16-
let index = indices[iteration]
17-
1814
do {
19-
let transformed = try transform(self[index])
15+
let transformed = try transform(self[indices[iteration]])
2016
queue.sync {
21-
results.append((index, .success(transformed)))
17+
results[iteration] = .success(transformed)
2218
}
2319
} catch {
2420
queue.sync {
25-
results.append((index, .failure(error)))
21+
results[iteration] = .failure(error)
2622
}
2723
}
2824
}
2925

30-
return try results.sorted { $0.index < $1.index }
31-
.map { try $0.result.get() }
26+
return try results.map { try $0!.get() }
3227
}
3328

3429
func parallelCompactMap<T>(transform: (Element) throws -> T?) throws -> [T] {

0 commit comments

Comments
 (0)