@@ -73,13 +73,12 @@ extension LazyChunked: LazyCollectionProtocol {
73
73
}
74
74
}
75
75
76
- /// Returns the index in the base collection for the first element that
77
- /// doesn't match the current chunk .
76
+ /// Returns the index in the base collection of the end of the chunk starting
77
+ /// at the given index .
78
78
@usableFromInline
79
- internal func endOfChunk( from i: Base . Index ) -> Base . Index {
80
- guard i != base. endIndex else { return base. endIndex }
81
- let subject = projection ( base [ i] )
82
- return base [ base. index ( after: i) ... ]
79
+ internal func endOfChunk( startingAt start: Base . Index ) -> Base . Index {
80
+ let subject = projection ( base [ start] )
81
+ return base [ base. index ( after: start) ... ]
83
82
. firstIndex ( where: { !belongInSameGroup( subject, projection ( $0) ) } )
84
83
?? base. endIndex
85
84
}
@@ -91,20 +90,21 @@ extension LazyChunked: LazyCollectionProtocol {
91
90
92
91
@inlinable
93
92
public var endIndex : Index {
94
- Index ( lowerBound: base. endIndex, upperBound : base . endIndex )
93
+ Index ( lowerBound: base. endIndex)
95
94
}
96
95
97
96
@inlinable
98
97
public func index( after i: Index ) -> Index {
99
- let upperBound = i. upperBound ?? endOfChunk ( from: i. lowerBound)
100
- let end = endOfChunk ( from: upperBound)
98
+ let upperBound = i. upperBound ?? endOfChunk ( startingAt: i. lowerBound)
99
+ guard upperBound != base. endIndex else { return endIndex }
100
+ let end = endOfChunk ( startingAt: upperBound)
101
101
return Index ( lowerBound: upperBound, upperBound: end)
102
102
}
103
103
104
104
@inlinable
105
105
public subscript( position: Index ) -> Base . SubSequence {
106
106
let upperBound = position. upperBound
107
- ?? endOfChunk ( from : position. lowerBound)
107
+ ?? endOfChunk ( startingAt : position. lowerBound)
108
108
return base [ position. lowerBound..< upperBound]
109
109
}
110
110
}
@@ -114,8 +114,8 @@ extension LazyChunked.Index: Hashable where Base.Index: Hashable {}
114
114
extension LazyChunked : BidirectionalCollection
115
115
where Base: BidirectionalCollection
116
116
{
117
- /// Returns the index in the base collection for the element that starts
118
- /// the chunk ending at the given index.
117
+ /// Returns the index in the base collection of the start of the chunk ending
118
+ /// at the given index.
119
119
@usableFromInline
120
120
internal func startOfChunk( endingAt end: Base . Index ) -> Base . Index {
121
121
let indexBeforeEnd = base. index ( before: end)
0 commit comments