chloro-pn commented on code in PR #6178:
URL: https://github.com/apache/arrow-rs/pull/6178#discussion_r1705832192


##########
arrow-select/src/filter.rs:
##########
@@ -707,6 +710,62 @@ fn filter_byte_view<T: ByteViewType>(
     GenericByteViewArray::from(unsafe { builder.build_unchecked() })
 }
 
+fn filter_fixed_size_binary(
+    array: &FixedSizeBinaryArray,
+    predicate: &FilterPredicate,
+) -> FixedSizeBinaryArray {
+    let values: &[u8] = array.values();
+    let value_length = array.value_length() as usize;
+    let calcualte_offset_from_index = |index: usize| index * value_length;
+    let buffer = match &predicate.strategy {
+        IterationStrategy::SlicesIterator => {
+            let mut buffer = MutableBuffer::with_capacity(predicate.count * 
value_length);
+            for (start, end) in SlicesIterator::new(&predicate.filter) {
+                buffer.extend_from_slice(
+                    
&values[calcualte_offset_from_index(start)..calcualte_offset_from_index(end)],
+                );
+            }
+            buffer
+        }
+        IterationStrategy::Slices(slices) => {
+            let mut buffer = MutableBuffer::with_capacity(predicate.count * 
value_length);
+            for (start, end) in slices {
+                buffer.extend_from_slice(
+                    
&values[calcualte_offset_from_index(*start)..calcualte_offset_from_index(*end)],
+                );
+            }
+            buffer
+        }
+        IterationStrategy::IndexIterator => {
+            let iter = IndexIterator::new(&predicate.filter, 
predicate.count).map(|x| {
+                
&values[calcualte_offset_from_index(x)..calcualte_offset_from_index(x + 1)]
+            });
+
+            // SAFETY: IndexIterator is trusted length
+            unsafe { MutableBuffer::from_trusted_len_iter_slice_u8(iter, 
value_length) }

Review Comment:
   The reason for implementing the `from_trusted_len_iter_slice_u8` method is 
that it involves performing memory copy operations based on `value_length`:
   ```
           for item in iterator {
               // note how there is no reserve here (compared with 
`extend_from_iter`)
               let src = item.to_byte_slice().as_ptr();
               std::ptr::copy_nonoverlapping(src, dst, item_size);
               dst = dst.add(item_size);
           }
   ```
   If we continue to use the `extend_from_slice`, we will have to perform 
memory copy operations according to the size of `u8`. As far as I know, in many 
platforms, memory copy operations are optimized through SIMD instructions, so 
copying multiple bytes at once obviously has better performance.



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