@@ -89,7 +89,7 @@ public struct CompactedCollection<Base: Collection, Element>: Collection
89
89
90
90
@inlinable
91
91
public func index( after i: Index ) -> Index {
92
- guard i != endIndex else {
92
+ guard i < endIndex else {
93
93
fatalError ( " Index out of bounds " )
94
94
}
95
95
let baseIdx = base. index ( after: i. base)
@@ -104,13 +104,14 @@ extension CompactedCollection: BidirectionalCollection
104
104
105
105
@inlinable
106
106
public func index( before i: Index ) -> Index {
107
- guard i != startIndex else {
107
+ guard i > startIndex else {
108
108
fatalError ( " Index out of bounds " )
109
109
}
110
110
111
- let baseIdx = base. index ( before: i. base)
112
- guard let idx = base [ ... baseIdx] . lastIndex ( where: { $0 != nil } )
113
- else { return Index ( base: base. startIndex) }
111
+ guard let idx =
112
+ base [ startIndex. base..< i. base]
113
+ . lastIndex ( where: { $0 != nil } )
114
+ else { fatalError ( " Index out of bounds " ) }
114
115
return Index ( base: idx)
115
116
}
116
117
}
@@ -150,46 +151,42 @@ extension CompactedCollection: LazyCollectionProtocol
150
151
// Hashable and Equatable conformance are based on each non-nil
151
152
// element on base collection.
152
153
extension CompactedSequence : Equatable
153
- where Base: Equatable , Base . Element: Equatable {
154
+ where Base. Element: Equatable {
154
155
155
156
@inlinable
156
157
public static func == ( lhs: CompactedSequence ,
157
158
rhs: CompactedSequence ) -> Bool {
158
- lhs. compactMap ( { $0 } )
159
- . elementsEqual ( rhs. compactMap ( { $0 } ) )
159
+ lhs. elementsEqual ( rhs)
160
160
}
161
161
}
162
162
163
163
extension CompactedSequence : Hashable
164
- where Base : Hashable , Base . Element: Hashable {
164
+ where Element: Hashable {
165
165
@inlinable
166
166
public func hash( into hasher: inout Hasher ) {
167
- for element in base {
168
- guard let unwrapped = element else { continue }
169
- hasher. combine ( unwrapped)
167
+ for element in self {
168
+ hasher. combine ( element)
170
169
}
171
170
}
172
171
}
173
172
174
173
extension CompactedCollection : Equatable
175
- where Base: Equatable , Base . Element: Equatable {
174
+ where Base. Element: Equatable {
176
175
177
176
@inlinable
178
177
public static func == ( lhs: CompactedCollection ,
179
178
rhs: CompactedCollection ) -> Bool {
180
- lhs. compactMap ( { $0 } )
181
- . elementsEqual ( rhs. compactMap ( { $0 } ) )
179
+ lhs. elementsEqual ( rhs)
182
180
}
183
181
}
184
182
185
183
extension CompactedCollection : Hashable
186
- where Base : Hashable , Base . Element: Hashable {
184
+ where Element: Hashable {
187
185
188
186
@inlinable
189
187
public func hash( into hasher: inout Hasher ) {
190
- for element in base {
191
- guard let unwrapped = element else { continue }
192
- hasher. combine ( unwrapped)
188
+ for element in self {
189
+ hasher. combine ( element)
193
190
}
194
191
}
195
192
}
0 commit comments