alamb commented on code in PR #9229:
URL: https://github.com/apache/arrow-rs/pull/9229#discussion_r2708452569


##########
arrow-select/src/filter.rs:
##########
@@ -91,6 +91,24 @@ impl<'a> IndexIterator<'a> {
         let iter = filter.values().set_indices();
         Self { remaining, iter }
     }
+
+    /// Collect this iterator as a [`Vec`]
+    pub fn collect(mut self) -> Vec<usize> {
+        let len = self.remaining;
+        let mut result = Vec::with_capacity(len);
+        let ptr: *mut usize = result.as_mut_ptr();
+        for i in 0..len {
+            // SAFETY: we have allocated enough space in `result`

Review Comment:
   I think it also relies on self.iter.next() being correctly synchronized with 
self.remaining. 
   
   Maybe we can add a debug assert to validate that assertion ?
   
   



##########
arrow-buffer/src/util/bit_iterator.rs:
##########
@@ -305,12 +305,12 @@ impl<'a> BitIndexIterator<'a> {
 impl Iterator for BitIndexIterator<'_> {
     type Item = usize;
 
-    #[inline]
+    #[inline(always)]
     fn next(&mut self) -> Option<Self::Item> {
         loop {
             if self.current_chunk != 0 {
                 let bit_pos = self.current_chunk.trailing_zeros();
-                self.current_chunk ^= 1 << bit_pos;
+                self.current_chunk &= self.current_chunk - 1;

Review Comment:
   fascinating



##########
arrow-select/src/filter.rs:
##########
@@ -91,6 +91,24 @@ impl<'a> IndexIterator<'a> {
         let iter = filter.values().set_indices();
         Self { remaining, iter }
     }
+
+    /// Collect this iterator as a [`Vec`]
+    pub fn collect(mut self) -> Vec<usize> {

Review Comment:
   Maybe it is worth a comment explaining that we can avoid this code when 
TrustedLengh is stable



-- 
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]

Reply via email to