alamb commented on code in PR #1865:
URL: https://github.com/apache/arrow-rs/pull/1865#discussion_r897968381
##########
arrow/src/compute/kernels/filter.rs:
##########
@@ -165,47 +97,28 @@ impl<'a> Iterator for SlicesIterator<'a> {
/// This provides the best performance on most predicates, apart from those
which keep
/// large runs and therefore favour [`SlicesIterator`]
struct IndexIterator<'a> {
- current_chunk: u64,
- chunk_offset: i64,
remaining: usize,
- iter: UnalignedBitChunkIterator<'a>,
+ iter: BitIndexIterator<'a>,
}
impl<'a> IndexIterator<'a> {
- fn new(filter: &'a BooleanArray, len: usize) -> Self {
+ fn new(filter: &'a BooleanArray, remaining: usize) -> Self {
assert_eq!(filter.null_count(), 0);
let data = filter.data();
- let chunks =
- UnalignedBitChunk::new(&data.buffers()[0], data.offset(),
data.len());
- let mut iter = chunks.iter();
-
- let current_chunk = iter.next().unwrap_or(0);
- let chunk_offset = -(chunks.lead_padding() as i64);
-
- Self {
- current_chunk,
- chunk_offset,
- remaining: len,
- iter,
- }
+ let iter = BitIndexIterator::new(&data.buffers()[0], data.offset(),
data.len());
+ Self { remaining, iter }
}
}
impl<'a> Iterator for IndexIterator<'a> {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
- while self.remaining != 0 {
- if self.current_chunk != 0 {
- let bit_pos = self.current_chunk.trailing_zeros();
- self.current_chunk ^= 1 << bit_pos;
- self.remaining -= 1;
- return Some((self.chunk_offset + bit_pos as i64) as usize);
- }
-
+ if self.remaining != 0 {
+ let next = self.iter.next().expect("IndexIterator exhausted
early");
Review Comment:
```suggestion
// Fascinatingly swapping these two lines around results in a
50%
// performance regression for some benchmarks
let next = self.iter.next().expect("IndexIterator exhausted
early");
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]