@@ -39,7 +39,7 @@ public struct LazySplitCollection<Base: Collection> {
39
39
self . _endIndex = Index (
40
40
baseRange: base. endIndex..< base. endIndex,
41
41
sequenceLength: Int . max,
42
- separatorCount : Int . max
42
+ splitCount : Int . max
43
43
)
44
44
45
45
/// We precalculate `startIndex`. There are three possibilities:
@@ -48,7 +48,7 @@ public struct LazySplitCollection<Base: Collection> {
48
48
self . _startIndex = Index (
49
49
baseRange: base. startIndex..< base. startIndex,
50
50
sequenceLength: 1 ,
51
- separatorCount : 0
51
+ splitCount : 0
52
52
)
53
53
if base. isEmpty {
54
54
if omittingEmptySubsequences {
@@ -61,7 +61,7 @@ public struct LazySplitCollection<Base: Collection> {
61
61
_startIndex = indexForSubsequence (
62
62
atOrAfter: base. startIndex,
63
63
sequenceLength: 0 ,
64
- separatorCount : 0
64
+ splitCount : 0
65
65
)
66
66
}
67
67
}
@@ -75,16 +75,16 @@ extension LazySplitCollection: LazyCollectionProtocol {
75
75
/// The number of subsequences up to and including this position in the
76
76
/// collection.
77
77
internal let sequenceLength : Int
78
- internal let separatorCount : Int
78
+ internal let splitCount : Int
79
79
80
80
internal init (
81
81
baseRange: Range < Base . Index > ,
82
82
sequenceLength: Int ,
83
- separatorCount : Int
83
+ splitCount : Int
84
84
) {
85
85
self . baseRange = baseRange
86
86
self . sequenceLength = sequenceLength
87
- self . separatorCount = separatorCount
87
+ self . splitCount = splitCount
88
88
}
89
89
90
90
public static func == ( lhs: Index , rhs: Index ) -> Bool {
@@ -102,18 +102,15 @@ extension LazySplitCollection: LazyCollectionProtocol {
102
102
internal func indexForSubsequence(
103
103
atOrAfter lowerBound: Base . Index ,
104
104
sequenceLength: Int ,
105
- separatorCount : Int
105
+ splitCount : Int
106
106
) -> Index {
107
- var newSeparatorCount = separatorCount
108
107
var start = lowerBound
109
108
// If we don't have any more splits to do (which we'll determine shortly),
110
- // the end of the next subsequence will be the end of the base collection.
109
+ // the end of this subsequence will be the end of the base collection.
111
110
var end = base. endIndex
112
111
113
- // The number of separators encountered thus far is identical to the number
114
- // of splits performed thus far.
115
- if newSeparatorCount < maxSplits {
116
- // The non-inclusive end of the next subsequence is marked by the next
112
+ if splitCount < maxSplits {
113
+ // The non-inclusive end of this subsequence is marked by the next
117
114
// separator, or the end of the base collection.
118
115
end =
119
116
base [ start... ] . firstIndex ( where: isSeparator)
@@ -134,14 +131,18 @@ extension LazySplitCollection: LazyCollectionProtocol {
134
131
}
135
132
}
136
133
134
+ var updatedSplitCount = splitCount
137
135
if end < base. endIndex {
138
- newSeparatorCount += 1
136
+ // This subsequence ends on a separator (and perhaps includes other
137
+ // separators, if we're omitting empty subsequences), so we've performed
138
+ // another split.
139
+ updatedSplitCount += 1
139
140
}
140
141
141
142
return Index (
142
143
baseRange: start..< end,
143
144
sequenceLength: sequenceLength + 1 ,
144
- separatorCount : newSeparatorCount
145
+ splitCount : updatedSplitCount
145
146
)
146
147
}
147
148
@@ -166,7 +167,7 @@ extension LazySplitCollection: LazyCollectionProtocol {
166
167
167
168
guard subsequenceStart != base. endIndex else {
168
169
if !omittingEmptySubsequences
169
- && i. sequenceLength < i. separatorCount + 1
170
+ && i. sequenceLength < i. splitCount + 1
170
171
{
171
172
/// The base collection ended with a separator, so we need to emit one
172
173
/// more empty subsequence. This one differs from `endIndex` in its
@@ -175,7 +176,7 @@ extension LazySplitCollection: LazyCollectionProtocol {
175
176
return Index (
176
177
baseRange: base. endIndex..< base. endIndex,
177
178
sequenceLength: i. sequenceLength + 1 ,
178
- separatorCount : i. separatorCount
179
+ splitCount : i. splitCount
179
180
)
180
181
} else {
181
182
return endIndex
@@ -185,7 +186,7 @@ extension LazySplitCollection: LazyCollectionProtocol {
185
186
return indexForSubsequence (
186
187
atOrAfter: subsequenceStart,
187
188
sequenceLength: i. sequenceLength,
188
- separatorCount : i. separatorCount
189
+ splitCount : i. splitCount
189
190
)
190
191
}
191
192
0 commit comments