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 @@ -213,27 +213,3 @@ actor SyntacticTestIndex {
213
213
return await readTask. value
214
214
}
215
215
}
216
-
217
- fileprivate extension Collection {
218
- /// Partition the elements of the collection into `numberOfBatches` roughly equally sized batches.
219
- ///
220
- /// Elements are assigned to the batches round-robin. This ensures that elements that are close to each other in the
221
- /// original collection end up in different batches. This is important because eg. test files will live close to each
222
- /// other in the file system and test scanning wants to scan them in different batches so we don't end up with one
223
- /// batch only containing source files and the other only containing test files.
224
- func partition( intoNumberOfBatches numberOfBatches: Int ) -> [ [ Element ] ] {
225
- var batches : [ [ Element ] ] = Array (
226
- repeating: {
227
- var batch : [ Element ] = [ ]
228
- batch. reserveCapacity ( self . count / numberOfBatches)
229
- return batch
230
- } ( ) ,
231
- count: numberOfBatches
232
- )
233
-
234
- for (index, element) in self . enumerated ( ) {
235
- batches [ index % numberOfBatches] . append ( element)
236
- }
237
- return batches. filter { !$0. isEmpty }
238
- }
239
- }
You can’t perform that action at this time.
0 commit comments