@@ -56,7 +56,12 @@ impl<'a, T: ArrowPrimitiveType> std::iter::Iterator for PrimitiveIter<'a, T> {
56
56
} else {
57
57
let old = self . current ;
58
58
self . current += 1 ;
59
- Some ( Some ( self . array . value ( old) ) )
59
+ // Safety:
60
+ // we just checked bounds in `self.current_end == self.current`
61
+ // this is safe on the premise that this struct is initialized with
62
+ // current = array.len()
63
+ // and that current_end is ever only decremented
64
+ unsafe { Some ( Some ( self . array . value_unchecked ( old) ) ) }
60
65
}
61
66
}
62
67
@@ -77,7 +82,12 @@ impl<'a, T: ArrowPrimitiveType> std::iter::DoubleEndedIterator for PrimitiveIter
77
82
Some ( if self . array . is_null ( self . current_end ) {
78
83
None
79
84
} else {
80
- Some ( self . array . value ( self . current_end ) )
85
+ // Safety:
86
+ // we just checked bounds in `self.current_end == self.current`
87
+ // this is safe on the premise that this struct is initialized with
88
+ // current = array.len()
89
+ // and that current_end is ever only decremented
90
+ unsafe { Some ( self . array . value_unchecked ( self . current_end ) ) }
81
91
} )
82
92
}
83
93
}
@@ -118,7 +128,12 @@ impl<'a> std::iter::Iterator for BooleanIter<'a> {
118
128
} else {
119
129
let old = self . current ;
120
130
self . current += 1 ;
121
- Some ( Some ( self . array . value ( old) ) )
131
+ // Safety:
132
+ // we just checked bounds in `self.current_end == self.current`
133
+ // this is safe on the premise that this struct is initialized with
134
+ // current = array.len()
135
+ // and that current_end is ever only decremented
136
+ unsafe { Some ( Some ( self . array . value_unchecked ( old) ) ) }
122
137
}
123
138
}
124
139
@@ -139,7 +154,12 @@ impl<'a> std::iter::DoubleEndedIterator for BooleanIter<'a> {
139
154
Some ( if self . array . is_null ( self . current_end ) {
140
155
None
141
156
} else {
142
- Some ( self . array . value ( self . current_end ) )
157
+ // Safety:
158
+ // we just checked bounds in `self.current_end == self.current`
159
+ // this is safe on the premise that this struct is initialized with
160
+ // current = array.len()
161
+ // and that current_end is ever only decremented
162
+ unsafe { Some ( self . array . value_unchecked ( self . current_end ) ) }
143
163
} )
144
164
}
145
165
}
@@ -182,7 +202,12 @@ impl<'a, T: StringOffsetSizeTrait> std::iter::Iterator for GenericStringIter<'a,
182
202
Some ( None )
183
203
} else {
184
204
self . current += 1 ;
185
- Some ( Some ( self . array . value ( i) ) )
205
+ // Safety:
206
+ // we just checked bounds in `self.current_end == self.current`
207
+ // this is safe on the premise that this struct is initialized with
208
+ // current = array.len()
209
+ // and that current_end is ever only decremented
210
+ unsafe { Some ( Some ( self . array . value_unchecked ( i) ) ) }
186
211
}
187
212
}
188
213
@@ -205,7 +230,12 @@ impl<'a, T: StringOffsetSizeTrait> std::iter::DoubleEndedIterator
205
230
Some ( if self . array . is_null ( self . current_end ) {
206
231
None
207
232
} else {
208
- Some ( self . array . value ( self . current_end ) )
233
+ // Safety:
234
+ // we just checked bounds in `self.current_end == self.current`
235
+ // this is safe on the premise that this struct is initialized with
236
+ // current = array.len()
237
+ // and that current_end is ever only decremented
238
+ unsafe { Some ( self . array . value_unchecked ( self . current_end ) ) }
209
239
} )
210
240
}
211
241
}
@@ -251,7 +281,12 @@ impl<'a, T: BinaryOffsetSizeTrait> std::iter::Iterator for GenericBinaryIter<'a,
251
281
Some ( None )
252
282
} else {
253
283
self . current += 1 ;
254
- Some ( Some ( self . array . value ( i) ) )
284
+ // Safety:
285
+ // we just checked bounds in `self.current_end == self.current`
286
+ // this is safe on the premise that this struct is initialized with
287
+ // current = array.len()
288
+ // and that current_end is ever only decremented
289
+ unsafe { Some ( Some ( self . array . value_unchecked ( i) ) ) }
255
290
}
256
291
}
257
292
@@ -274,7 +309,12 @@ impl<'a, T: BinaryOffsetSizeTrait> std::iter::DoubleEndedIterator
274
309
Some ( if self . array . is_null ( self . current_end ) {
275
310
None
276
311
} else {
277
- Some ( self . array . value ( self . current_end ) )
312
+ // Safety:
313
+ // we just checked bounds in `self.current_end == self.current`
314
+ // this is safe on the premise that this struct is initialized with
315
+ // current = array.len()
316
+ // and that current_end is ever only decremented
317
+ unsafe { Some ( self . array . value_unchecked ( self . current_end ) ) }
278
318
} )
279
319
}
280
320
}
@@ -318,7 +358,12 @@ impl<'a, S: OffsetSizeTrait> std::iter::Iterator for GenericListArrayIter<'a, S>
318
358
Some ( None )
319
359
} else {
320
360
self . current += 1 ;
321
- Some ( Some ( self . array . value ( i) ) )
361
+ // Safety:
362
+ // we just checked bounds in `self.current_end == self.current`
363
+ // this is safe on the premise that this struct is initialized with
364
+ // current = array.len()
365
+ // and that current_end is ever only decremented
366
+ unsafe { Some ( Some ( self . array . value_unchecked ( i) ) ) }
322
367
}
323
368
}
324
369
@@ -341,7 +386,12 @@ impl<'a, S: OffsetSizeTrait> std::iter::DoubleEndedIterator
341
386
Some ( if self . array . is_null ( self . current_end ) {
342
387
None
343
388
} else {
344
- Some ( self . array . value ( self . current_end ) )
389
+ // Safety:
390
+ // we just checked bounds in `self.current_end == self.current`
391
+ // this is safe on the premise that this struct is initialized with
392
+ // current = array.len()
393
+ // and that current_end is ever only decremented
394
+ unsafe { Some ( self . array . value_unchecked ( self . current_end ) ) }
345
395
} )
346
396
}
347
397
}
0 commit comments