diff --git a/src/array/struct_/iterator.rs b/src/array/struct_/iterator.rs index ee5bd54aa96..57ee095be98 100644 --- a/src/array/struct_/iterator.rs +++ b/src/array/struct_/iterator.rs @@ -34,14 +34,15 @@ impl<'a> Iterator for StructValueIter<'a> { let old = self.index; self.index += 1; - let mut item = vec![]; - for i in 0..self.array.fields().len() { - let arr = self.array.value(i); - item.push(new_scalar(arr.as_ref(), old)) - } // Safety: // self.end is maximized by the length of the array - Some(item) + Some( + self.array + .values() + .iter() + .map(|v| new_scalar(v.as_ref(), old)) + .collect(), + ) } #[inline] @@ -60,14 +61,15 @@ impl<'a> DoubleEndedIterator for StructValueIter<'a> { } else { self.end -= 1; - let mut item = vec![]; - for i in 0..self.array.fields().len() { - let arr = self.array.value(i); - item.push(new_scalar(arr.as_ref(), self.end)) - } // Safety: // self.end is maximized by the length of the array - Some(item) + Some( + self.array + .values() + .iter() + .map(|v| new_scalar(v.as_ref(), self.end)) + .collect(), + ) } } } diff --git a/src/array/struct_/mod.rs b/src/array/struct_/mod.rs index a03c0786ff4..c54be876809 100644 --- a/src/array/struct_/mod.rs +++ b/src/array/struct_/mod.rs @@ -1,4 +1,4 @@ -use std::{ops::Index, sync::Arc}; +use std::sync::Arc; use crate::{ bitmap::Bitmap, @@ -169,11 +169,6 @@ impl StructArray { pub fn fields(&self) -> &[Field] { Self::get_fields(&self.data_type) } - - /// Returns the element at index `i` - pub fn value(&self, index: usize) -> &Arc { - self.values().index(index) - } } impl StructArray {