@@ -25,7 +25,10 @@ final class FlattenDistanceFromToTests {
25
25
let tests = FlattenDistanceFromToTests ( )
26
26
let suite = TestSuite ( " FlattenDistanceFromToTests " )
27
27
suite. test ( " EachIndexPair " , tests. testEachIndexPair)
28
- suite. test ( " MinMaxOutputs " , tests. testMinMaxOutputs)
28
+ if #available( SwiftStdlib 6 . 0 , * ) {
29
+ // The random access time complexity was fixed in Swift 6.0.
30
+ suite. test ( " MinMaxRandomAccess " , tests. testMinMaxRandomAccess)
31
+ }
29
32
runAllTests ( )
30
33
}
31
34
}
@@ -50,7 +53,7 @@ extension FlattenDistanceFromToTests {
50
53
/// ─────────────────
51
54
/// [][1][2,2][3,3,3]
52
55
///
53
- func forEachLaneSizeCase(
56
+ private func forEachLaneSizeCase(
54
57
through limits: [ Int ] ,
55
58
perform action: ( [ [ Int ] ] ) -> Void
56
59
) {
@@ -61,19 +64,18 @@ extension FlattenDistanceFromToTests {
61
64
62
65
if array [ index] . count < limits [ index] {
63
66
array [ index] . append ( index)
64
- continue
65
- }
66
-
67
- while index < limits. endIndex, array [ index] . count == limits [ index] {
68
- array. formIndex ( after: & index)
69
- }
70
-
71
- if index < limits. endIndex {
72
- array [ index] . append ( index)
67
+ } else {
68
+ while index < limits. endIndex, array [ index] . count == limits [ index] {
69
+ array. formIndex ( after: & index)
70
+ }
73
71
74
- while index > array. startIndex {
75
- array. formIndex ( before: & index)
76
- array [ index] . removeAll ( keepingCapacity: true )
72
+ if index < limits. endIndex {
73
+ array [ index] . append ( index)
74
+
75
+ while index > array. startIndex {
76
+ array. formIndex ( before: & index)
77
+ array [ index] . removeAll ( keepingCapacity: true )
78
+ }
77
79
}
78
80
}
79
81
}
@@ -88,10 +90,10 @@ extension FlattenDistanceFromToTests {
88
90
/// offset: 2, index: 1,1
89
91
/// offset: 3, index: 2
90
92
///
91
- func forEachEnumeratedIndexIncludingEndIndex< T: Collection > (
93
+ private func forEachEnumeratedIndexIncludingEndIndex< T> (
92
94
in collection: T ,
93
95
perform action: ( ( offset: Int , index: T . Index ) ) -> Void
94
- ) {
96
+ ) where T : Collection {
95
97
var state = ( offset: 0 , index: collection. startIndex)
96
98
while true {
97
99
action ( state)
@@ -148,11 +150,15 @@ extension FlattenDistanceFromToTests {
148
150
149
151
extension FlattenDistanceFromToTests {
150
152
151
- /// Checks some `Int.min` and `Int.max` distances.
153
+ /// Checks some `Int.min` and `Int.max` distances with random access.
154
+ ///
155
+ /// It needs Swift 6.0+ because prior versions find the distance by
156
+ /// iterating from one index to the other, which takes way too long.
152
157
///
153
158
/// - Note: A distance of `Int.min` requires more than `Int.max` elements.
154
159
///
155
- func testMinMaxOutputs( ) {
160
+ @available ( SwiftStdlib 6 . 0 , * )
161
+ func testMinMaxRandomAccess( ) {
156
162
for s : FlattenSequence in [
157
163
158
164
[ - 1 ..< Int . max/ 1 ] ,
0 commit comments