jhorstmann commented on code in PR #10172:
URL: https://github.com/apache/arrow-rs/pull/10172#discussion_r3455629926


##########
parquet/src/util/bit_util.rs:
##########
@@ -71,21 +81,82 @@ macro_rules! from_le_bytes {
                 <$ty>::from_le_bytes(bs)
             }
         }
-        impl FromBitpacked for $ty {
-            #[inline]
-            fn from_u64(v: u64) -> Self {
-                v as Self
-            }
-        }
         )*
     };
 }
 
+macro_rules! from_bitpacked {
+    ($($ty: ty => $unpack: path),*) => {
+        $(
+            impl FromBitpacked for $ty {
+                const BIT_CAPACITY: usize = std::mem::size_of::<$ty>() * 8;
+                // this has to match the signature of the unpack* functions
+                const BATCH_SIZE: usize = std::mem::size_of::<$ty>() * 8;
+
+                #[inline]
+                fn from_u64(v: u64) -> Self {
+                    v as _
+                }
+
+                #[inline]
+                fn unpack_batch(input: &[u8], output: &mut [Self], num_bits: 
usize) {
+                    $unpack(input, (&mut 
output[..Self::BATCH_SIZE]).try_into().unwrap(), num_bits)
+                }
+            }
+        )*
+    }
+}
+
+macro_rules! from_bitpacked_delegate {
+    ($($ty: ty => $delegate: ty),*) => {
+        $(
+            impl FromBitpacked for $ty {
+                const BIT_CAPACITY: usize = <$delegate as 
FromBitpacked>::BIT_CAPACITY;
+                const BATCH_SIZE: usize = <$delegate as 
FromBitpacked>::BATCH_SIZE;
+
+                fn from_u64(v: u64) -> Self {
+                    v as _
+                }
+
+                fn unpack_batch(input: &[u8], output: &mut [Self], num_bits: 
usize) {
+                    const {

Review Comment:
   `transmute` does not really require the same alignment, will keep the 
current assert on size and layout.



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