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

Commit

Permalink
Fix the loop by using the iterator pattern instead of the for loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
illumination-k committed Nov 18, 2021
1 parent 8329703 commit ba1ca05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
26 changes: 14 additions & 12 deletions src/array/struct_/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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(),
)
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/array/struct_/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ops::Index, sync::Arc};
use std::sync::Arc;

use crate::{
bitmap::Bitmap,
Expand Down Expand Up @@ -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<dyn Array> {
self.values().index(index)
}
}

impl StructArray {
Expand Down

0 comments on commit ba1ca05

Please sign in to comment.