This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git


The following commit(s) were added to refs/heads/main by this push:
     new fa95f1b2 chore: Remove unsafe use of from_raw_parts in Parquet decoder 
(#549)
fa95f1b2 is described below

commit fa95f1b253bf339e214b0ce642c68fb7007b5dc0
Author: Andy Grove <[email protected]>
AuthorDate: Tue Jun 11 07:17:04 2024 -0600

    chore: Remove unsafe use of from_raw_parts in Parquet decoder (#549)
    
    * refactor make_int_variant_impl to remove unsafe use of from_raw_parts
    
    * fix
    
    * refactor
    
    * smaller change
    
    * remove commented out code
    
    * remove in_ptr
    
    * simplify
---
 core/src/parquet/read/values.rs | 36 ++++--------------------------------
 1 file changed, 4 insertions(+), 32 deletions(-)

diff --git a/core/src/parquet/read/values.rs b/core/src/parquet/read/values.rs
index 9d9bbb3c..c2b1b6e6 100644
--- a/core/src/parquet/read/values.rs
+++ b/core/src/parquet/read/values.rs
@@ -443,49 +443,21 @@ macro_rules! make_int_variant_impl {
     ($ty: ident, $native_ty: ty, $type_size: expr) => {
         impl PlainDecoding for $ty {
             fn decode(src: &mut PlainDecoderInner, dst: &mut 
ParquetMutableVector, num: usize) {
-                let num_bytes = 4 * num; // Parquet stores Int8/Int16 using 4 
bytes
-
                 let src_data = &src.data;
-                let mut src_offset = src.offset;
                 let dst_slice = dst.value_buffer.as_slice_mut();
                 let mut dst_offset = dst.num_values * $type_size;
-
-                let mut i = 0;
-                let mut in_ptr = &src_data[src_offset..] as *const [u8] as 
*const u8 as *const u32;
-
-                while num - i >= 32 {
-                    unsafe {
-                        let in_slice = std::slice::from_raw_parts(in_ptr, 32);
-
-                        for n in 0..32 {
-                            copy_nonoverlapping(
-                                in_slice[n..].as_ptr() as *const $native_ty,
-                                &mut dst_slice[dst_offset] as *mut u8 as *mut 
$native_ty,
-                                1,
-                            );
-                            i += 1;
-                            dst_offset += $type_size;
-                        }
-                        in_ptr = in_ptr.offset(32);
-                    }
-                }
-
-                src_offset += i * 4;
-
-                (0..(num - i)).for_each(|_| {
+                for _ in 0..num {
                     unsafe {
                         copy_nonoverlapping(
-                            &src_data[src_offset..] as *const [u8] as *const u8
+                            &src_data[src.offset..] as *const [u8] as *const u8
                                 as *const $native_ty,
                             &mut dst_slice[dst_offset] as *mut u8 as *mut 
$native_ty,
                             1,
                         );
                     }
-                    src_offset += 4;
+                    src.offset += 4; // Parquet stores Int8/Int16 using 4 bytes
                     dst_offset += $type_size;
-                });
-
-                src.offset += num_bytes;
+                }
             }
 
             fn skip(src: &mut PlainDecoderInner, num: usize) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to