Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Improved iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Dec 18, 2022
1 parent a2df894 commit fef36d2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/array/union/iterator.rs
Expand Up @@ -8,6 +8,7 @@ pub struct UnionIter<'a> {
}

impl<'a> UnionIter<'a> {
#[inline]
pub fn new(array: &'a UnionArray) -> Self {
Self { array, current: 0 }
}
Expand All @@ -16,16 +17,18 @@ impl<'a> UnionIter<'a> {
impl<'a> Iterator for UnionIter<'a> {
type Item = Box<dyn Scalar>;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.current == self.array.len() {
None
} else {
let old = self.current;
self.current += 1;
Some(self.array.value(old))
Some(unsafe { self.array.value_unchecked(old) })
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.array.len() - self.current;
(len, Some(len))
Expand Down

0 comments on commit fef36d2

Please sign in to comment.