File tree Expand file tree Collapse file tree 3 files changed +36
-24
lines changed Expand file tree Collapse file tree 3 files changed +36
-24
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ add_library(SKSupport STATIC
5
5
BuildConfiguration.swift
6
6
ByteString.swift
7
7
Collection+Only.swift
8
+ Collection+PartitionIntoBatches.swift
8
9
Connection+Send.swift
9
10
dlopen.swift
10
11
DocumentURI+CustomLogStringConvertible.swift
Original file line number Diff line number Diff line change
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ public extension Collection {
14
+ /// Partition the elements of the collection into `numberOfBatches` roughly equally sized batches.
15
+ ///
16
+ /// Elements are assigned to the batches round-robin. This ensures that elements that are close to each other in the
17
+ /// original collection end up in different batches. This is important because eg. test files will live close to each
18
+ /// other in the file system and test scanning wants to scan them in different batches so we don't end up with one
19
+ /// batch only containing source files and the other only containing test files.
20
+ func partition( intoNumberOfBatches numberOfBatches: Int ) -> [ [ Element ] ] {
21
+ var batches : [ [ Element ] ] = Array (
22
+ repeating: {
23
+ var batch : [ Element ] = [ ]
24
+ batch. reserveCapacity ( self . count / numberOfBatches)
25
+ return batch
26
+ } ( ) ,
27
+ count: numberOfBatches
28
+ )
29
+
30
+ for (index, element) in self . enumerated ( ) {
31
+ batches [ index % numberOfBatches] . append ( element)
32
+ }
33
+ return batches. filter { !$0. isEmpty }
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -211,27 +211,3 @@ actor SyntacticTestIndex {
211
211
return await readTask. value
212
212
}
213
213
}
214
-
215
- fileprivate extension Collection {
216
- /// Partition the elements of the collection into `numberOfBatches` roughly equally sized batches.
217
- ///
218
- /// Elements are assigned to the batches round-robin. This ensures that elements that are close to each other in the
219
- /// original collection end up in different batches. This is important because eg. test files will live close to each
220
- /// other in the file system and test scanning wants to scan them in different batches so we don't end up with one
221
- /// batch only containing source files and the other only containing test files.
222
- func partition( intoNumberOfBatches numberOfBatches: Int ) -> [ [ Element ] ] {
223
- var batches : [ [ Element ] ] = Array (
224
- repeating: {
225
- var batch : [ Element ] = [ ]
226
- batch. reserveCapacity ( self . count / numberOfBatches)
227
- return batch
228
- } ( ) ,
229
- count: numberOfBatches
230
- )
231
-
232
- for (index, element) in self . enumerated ( ) {
233
- batches [ index % numberOfBatches] . append ( element)
234
- }
235
- return batches. filter { !$0. isEmpty }
236
- }
237
- }
You can’t perform that action at this time.
0 commit comments