diff --git a/crates/polars-arrow/src/array/primitive/mod.rs b/crates/polars-arrow/src/array/primitive/mod.rs index 831a10c372cc..85353ecb5178 100644 --- a/crates/polars-arrow/src/array/primitive/mod.rs +++ b/crates/polars-arrow/src/array/primitive/mod.rs @@ -459,8 +459,8 @@ impl PrimitiveArray { // SAFETY: this is fine, we checked size and alignment, and NativeType // is always Pod. - assert_eq!(std::mem::size_of::(), std::mem::size_of::()); - assert_eq!(std::mem::align_of::(), std::mem::align_of::()); + assert_eq!(size_of::(), size_of::()); + assert_eq!(align_of::(), align_of::()); let new_values = unsafe { std::mem::transmute::, Buffer>(values) }; PrimitiveArray::new(U::PRIMITIVE.into(), new_values, validity) } diff --git a/crates/polars-arrow/src/bitmap/aligned.rs b/crates/polars-arrow/src/bitmap/aligned.rs index b5eab49432ca..ad1baf06631e 100644 --- a/crates/polars-arrow/src/bitmap/aligned.rs +++ b/crates/polars-arrow/src/bitmap/aligned.rs @@ -55,7 +55,7 @@ impl<'a, T: BitChunk> AlignedBitmapSlice<'a, T> { /// The length (in bits) of the portion of the bitmap found in bulk. #[inline(always)] pub fn bulk_bitlen(&self) -> usize { - 8 * std::mem::size_of::() * self.bulk.len() + 8 * size_of::() * self.bulk.len() } /// The length (in bits) of the portion of the bitmap found in suffix. @@ -77,7 +77,7 @@ impl<'a, T: BitChunk> AlignedBitmapSlice<'a, T> { offset %= 8; // Fast-path: fits entirely in one chunk. - let chunk_len = std::mem::size_of::(); + let chunk_len = size_of::(); let chunk_len_bits = 8 * chunk_len; if offset + len <= chunk_len_bits { let mut prefix = load_chunk_le::(bytes) >> offset; diff --git a/crates/polars-arrow/src/bitmap/bitmap_ops.rs b/crates/polars-arrow/src/bitmap/bitmap_ops.rs index a3edb658be4e..032c76710f66 100644 --- a/crates/polars-arrow/src/bitmap/bitmap_ops.rs +++ b/crates/polars-arrow/src/bitmap/bitmap_ops.rs @@ -12,7 +12,7 @@ pub(crate) fn push_bitchunk(buffer: &mut Vec, value: T) { /// Creates a [`Vec`] from a [`TrustedLen`] of [`BitChunk`]. pub fn chunk_iter_to_vec>(iter: I) -> Vec { - let cap = iter.size_hint().0 * std::mem::size_of::(); + let cap = iter.size_hint().0 * size_of::(); let mut buffer = Vec::with_capacity(cap); for v in iter { push_bitchunk(&mut buffer, v) @@ -24,7 +24,7 @@ fn chunk_iter_to_vec_and_remainder>( iter: I, remainder: T, ) -> Vec { - let cap = (iter.size_hint().0 + 1) * std::mem::size_of::(); + let cap = (iter.size_hint().0 + 1) * size_of::(); let mut buffer = Vec::with_capacity(cap); for v in iter { push_bitchunk(&mut buffer, v) diff --git a/crates/polars-arrow/src/bitmap/utils/chunk_iterator/chunks_exact.rs b/crates/polars-arrow/src/bitmap/utils/chunk_iterator/chunks_exact.rs index 7bc12e22898e..50f4e023ac1f 100644 --- a/crates/polars-arrow/src/bitmap/utils/chunk_iterator/chunks_exact.rs +++ b/crates/polars-arrow/src/bitmap/utils/chunk_iterator/chunks_exact.rs @@ -17,7 +17,7 @@ impl<'a, T: BitChunk> BitChunksExact<'a, T> { #[inline] pub fn new(bitmap: &'a [u8], length: usize) -> Self { assert!(length <= bitmap.len() * 8); - let size_of = std::mem::size_of::(); + let size_of = size_of::(); let bitmap = &bitmap[..length.saturating_add(7) / 8]; diff --git a/crates/polars-arrow/src/bitmap/utils/chunk_iterator/merge.rs b/crates/polars-arrow/src/bitmap/utils/chunk_iterator/merge.rs index 81e08df0059e..680d3bf96fa4 100644 --- a/crates/polars-arrow/src/bitmap/utils/chunk_iterator/merge.rs +++ b/crates/polars-arrow/src/bitmap/utils/chunk_iterator/merge.rs @@ -23,7 +23,7 @@ where // expected = [n5, n6, n7, c0, c1, c2, c3, c4] // 1. unset most significants of `next` up to `offset` - let inverse_offset = std::mem::size_of::() * 8 - offset; + let inverse_offset = size_of::() * 8 - offset; next <<= inverse_offset; // next = [n5, n6, n7, 0 , 0 , 0 , 0 , 0 ] diff --git a/crates/polars-arrow/src/bitmap/utils/chunk_iterator/mod.rs b/crates/polars-arrow/src/bitmap/utils/chunk_iterator/mod.rs index 8a1668a37d1f..7c387d65b10d 100644 --- a/crates/polars-arrow/src/bitmap/utils/chunk_iterator/mod.rs +++ b/crates/polars-arrow/src/bitmap/utils/chunk_iterator/mod.rs @@ -44,7 +44,7 @@ fn copy_with_merge(dst: &mut T::Bytes, bytes: &[u8], bit_offset: us bytes .windows(2) .chain(std::iter::once([bytes[bytes.len() - 1], 0].as_ref())) - .take(std::mem::size_of::()) + .take(size_of::()) .enumerate() .for_each(|(i, w)| { let val = merge_reversed(w[0], w[1], bit_offset); @@ -59,7 +59,7 @@ impl<'a, T: BitChunk> BitChunks<'a, T> { let slice = &slice[offset / 8..]; let bit_offset = offset % 8; - let size_of = std::mem::size_of::(); + let size_of = size_of::(); let bytes_len = len / 8; let bytes_upper_len = (len + bit_offset + 7) / 8; @@ -120,7 +120,7 @@ impl<'a, T: BitChunk> BitChunks<'a, T> { // all remaining bytes self.remainder_bytes .iter() - .take(std::mem::size_of::()) + .take(size_of::()) .enumerate() .for_each(|(i, val)| remainder[i] = *val); @@ -137,7 +137,7 @@ impl<'a, T: BitChunk> BitChunks<'a, T> { /// Returns the remainder bits in [`BitChunks::remainder`]. pub fn remainder_len(&self) -> usize { - self.len - (std::mem::size_of::() * ((self.len / 8) / std::mem::size_of::()) * 8) + self.len - (size_of::() * ((self.len / 8) / size_of::()) * 8) } } diff --git a/crates/polars-arrow/src/bitmap/utils/chunks_exact_mut.rs b/crates/polars-arrow/src/bitmap/utils/chunks_exact_mut.rs index 7a5a91a12805..04a9f8b661a7 100644 --- a/crates/polars-arrow/src/bitmap/utils/chunks_exact_mut.rs +++ b/crates/polars-arrow/src/bitmap/utils/chunks_exact_mut.rs @@ -4,7 +4,7 @@ use super::BitChunk; /// /// # Safety /// The slices returned by this iterator are guaranteed to have length equal to -/// `std::mem::size_of::()`. +/// `size_of::()`. #[derive(Debug)] pub struct BitChunksExactMut<'a, T: BitChunk> { chunks: std::slice::ChunksExactMut<'a, u8>, @@ -18,7 +18,7 @@ impl<'a, T: BitChunk> BitChunksExactMut<'a, T> { #[inline] pub fn new(bitmap: &'a mut [u8], length: usize) -> Self { assert!(length <= bitmap.len() * 8); - let size_of = std::mem::size_of::(); + let size_of = size_of::(); let bitmap = &mut bitmap[..length.saturating_add(7) / 8]; diff --git a/crates/polars-arrow/src/bitmap/utils/iterator.rs b/crates/polars-arrow/src/bitmap/utils/iterator.rs index c386b2d02db4..bba98ffbc704 100644 --- a/crates/polars-arrow/src/bitmap/utils/iterator.rs +++ b/crates/polars-arrow/src/bitmap/utils/iterator.rs @@ -176,7 +176,7 @@ impl<'a> BitmapIter<'a> { let num_words = n / 64; if num_words > 0 { - assert!(self.bytes.len() >= num_words * std::mem::size_of::()); + assert!(self.bytes.len() >= num_words * size_of::()); bitmap.extend_from_slice(self.bytes, 0, num_words * u64::BITS as usize); @@ -189,7 +189,7 @@ impl<'a> BitmapIter<'a> { return; } - assert!(self.bytes.len() >= std::mem::size_of::()); + assert!(self.bytes.len() >= size_of::()); self.word_len = usize::min(self.rest_len, 64); self.rest_len -= self.word_len; diff --git a/crates/polars-arrow/src/buffer/immutable.rs b/crates/polars-arrow/src/buffer/immutable.rs index 1dfe805ffc57..9e612427a315 100644 --- a/crates/polars-arrow/src/buffer/immutable.rs +++ b/crates/polars-arrow/src/buffer/immutable.rs @@ -299,10 +299,10 @@ impl From for Buffer { impl From> for arrow_buffer::Buffer { fn from(value: Buffer) -> Self { let offset = value.offset(); - value.storage.into_arrow_buffer().slice_with_length( - offset * std::mem::size_of::(), - value.length * std::mem::size_of::(), - ) + value + .storage + .into_arrow_buffer() + .slice_with_length(offset * size_of::(), value.length * size_of::()) } } diff --git a/crates/polars-arrow/src/compute/aggregate/memory.rs b/crates/polars-arrow/src/compute/aggregate/memory.rs index bd4ba7ab6384..1cf7512bbbef 100644 --- a/crates/polars-arrow/src/compute/aggregate/memory.rs +++ b/crates/polars-arrow/src/compute/aggregate/memory.rs @@ -18,7 +18,7 @@ macro_rules! dyn_binary { let values_end = offsets[offsets.len() - 1] as usize; values_end - values_start - + offsets.len() * std::mem::size_of::<$o>() + + offsets.len() * size_of::<$o>() + validity_size(array.validity()) }}; } @@ -50,7 +50,7 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize { }, Primitive(PrimitiveType::DaysMs) => { let array = array.as_any().downcast_ref::().unwrap(); - array.values().len() * std::mem::size_of::() * 2 + validity_size(array.validity()) + array.values().len() * size_of::() * 2 + validity_size(array.validity()) }, Primitive(primitive) => with_match_primitive_type_full!(primitive, |$T| { let array = array @@ -58,7 +58,7 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize { .downcast_ref::>() .unwrap(); - array.values().len() * std::mem::size_of::<$T>() + validity_size(array.validity()) + array.values().len() * size_of::<$T>() + validity_size(array.validity()) }), Binary => dyn_binary!(array, BinaryArray, i32), FixedSizeBinary => { @@ -74,7 +74,7 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize { List => { let array = array.as_any().downcast_ref::>().unwrap(); estimated_bytes_size(array.values().as_ref()) - + array.offsets().len_proxy() * std::mem::size_of::() + + array.offsets().len_proxy() * size_of::() + validity_size(array.validity()) }, FixedSizeList => { @@ -84,7 +84,7 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize { LargeList => { let array = array.as_any().downcast_ref::>().unwrap(); estimated_bytes_size(array.values().as_ref()) - + array.offsets().len_proxy() * std::mem::size_of::() + + array.offsets().len_proxy() * size_of::() + validity_size(array.validity()) }, Struct => { @@ -99,11 +99,11 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize { }, Union => { let array = array.as_any().downcast_ref::().unwrap(); - let types = array.types().len() * std::mem::size_of::(); + let types = array.types().len() * size_of::(); let offsets = array .offsets() .as_ref() - .map(|x| x.len() * std::mem::size_of::()) + .map(|x| x.len() * size_of::()) .unwrap_or_default(); let fields = array .fields() @@ -124,7 +124,7 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize { BinaryView => binview_size::<[u8]>(array.as_any().downcast_ref().unwrap()), Map => { let array = array.as_any().downcast_ref::().unwrap(); - let offsets = array.offsets().len_proxy() * std::mem::size_of::(); + let offsets = array.offsets().len_proxy() * size_of::(); offsets + estimated_bytes_size(array.field().as_ref()) + validity_size(array.validity()) }, } diff --git a/crates/polars-arrow/src/ffi/array.rs b/crates/polars-arrow/src/ffi/array.rs index d6b61f090329..4adf1b1c613c 100644 --- a/crates/polars-arrow/src/ffi/array.rs +++ b/crates/polars-arrow/src/ffi/array.rs @@ -225,11 +225,7 @@ unsafe fn get_buffer_ptr( ); } - if array - .buffers - .align_offset(std::mem::align_of::<*mut *const u8>()) - != 0 - { + if array.buffers.align_offset(align_of::<*mut *const u8>()) != 0 { polars_bail!( ComputeError: "an ArrowArray of type {dtype:?} must have buffer {index} aligned to type {}", @@ -294,7 +290,7 @@ unsafe fn create_buffer( // We have to check alignment. // This is the zero-copy path. - if ptr.align_offset(std::mem::align_of::()) == 0 { + if ptr.align_offset(align_of::()) == 0 { let storage = SharedStorage::from_internal_arrow_array(ptr, len, owner); Ok(Buffer::from_storage(storage).sliced(offset, len - offset)) } diff --git a/crates/polars-arrow/src/io/avro/read/deserialize.rs b/crates/polars-arrow/src/io/avro/read/deserialize.rs index 7c626f2b74ee..f2f8af90c167 100644 --- a/crates/polars-arrow/src/io/avro/read/deserialize.rs +++ b/crates/polars-arrow/src/io/avro/read/deserialize.rs @@ -195,9 +195,8 @@ fn deserialize_value<'a>( array.push(Some(value)) }, PrimitiveType::Float32 => { - let value = - f32::from_le_bytes(block[..std::mem::size_of::()].try_into().unwrap()); - block = &block[std::mem::size_of::()..]; + let value = f32::from_le_bytes(block[..size_of::()].try_into().unwrap()); + block = &block[size_of::()..]; let array = array .as_mut_any() .downcast_mut::>() @@ -205,9 +204,8 @@ fn deserialize_value<'a>( array.push(Some(value)) }, PrimitiveType::Float64 => { - let value = - f64::from_le_bytes(block[..std::mem::size_of::()].try_into().unwrap()); - block = &block[std::mem::size_of::()..]; + let value = f64::from_le_bytes(block[..size_of::()].try_into().unwrap()); + block = &block[size_of::()..]; let array = array .as_mut_any() .downcast_mut::>() @@ -404,10 +402,10 @@ fn skip_item<'a>( let _ = util::zigzag_i64(&mut block)?; }, PrimitiveType::Float32 => { - block = &block[std::mem::size_of::()..]; + block = &block[size_of::()..]; }, PrimitiveType::Float64 => { - block = &block[std::mem::size_of::()..]; + block = &block[size_of::()..]; }, PrimitiveType::MonthDayNano => { block = &block[12..]; diff --git a/crates/polars-arrow/src/io/ipc/read/read_basic.rs b/crates/polars-arrow/src/io/ipc/read/read_basic.rs index 09005ea4222e..9721137adf5c 100644 --- a/crates/polars-arrow/src/io/ipc/read/read_basic.rs +++ b/crates/polars-arrow/src/io/ipc/read/read_basic.rs @@ -17,10 +17,10 @@ fn read_swapped( is_little_endian: bool, ) -> PolarsResult<()> { // slow case where we must reverse bits - let mut slice = vec![0u8; length * std::mem::size_of::()]; + let mut slice = vec![0u8; length * size_of::()]; reader.read_exact(&mut slice)?; - let chunks = slice.chunks_exact(std::mem::size_of::()); + let chunks = slice.chunks_exact(size_of::()); if !is_little_endian { // machine is little endian, file is big endian buffer @@ -67,7 +67,7 @@ fn read_uncompressed_buffer( length: usize, is_little_endian: bool, ) -> PolarsResult> { - let required_number_of_bytes = length.saturating_mul(std::mem::size_of::()); + let required_number_of_bytes = length.saturating_mul(size_of::()); if required_number_of_bytes > buffer_length { polars_bail!( oos = OutOfSpecKind::InvalidBuffer { diff --git a/crates/polars-arrow/src/io/ipc/write/serialize/mod.rs b/crates/polars-arrow/src/io/ipc/write/serialize/mod.rs index f13098477d4d..43af5add63a6 100644 --- a/crates/polars-arrow/src/io/ipc/write/serialize/mod.rs +++ b/crates/polars-arrow/src/io/ipc/write/serialize/mod.rs @@ -283,7 +283,7 @@ fn _write_buffer_from_iter>( is_little_endian: bool, ) { let len = buffer.size_hint().0; - arrow_data.reserve(len * std::mem::size_of::()); + arrow_data.reserve(len * size_of::()); if is_little_endian { buffer .map(|x| T::to_le_bytes(&x)) @@ -303,7 +303,7 @@ fn _write_compressed_buffer_from_iter>( compression: Compression, ) { let len = buffer.size_hint().0; - let mut swapped = Vec::with_capacity(len * std::mem::size_of::()); + let mut swapped = Vec::with_capacity(len * size_of::()); if is_little_endian { buffer .map(|x| T::to_le_bytes(&x)) diff --git a/crates/polars-arrow/src/legacy/kernels/mod.rs b/crates/polars-arrow/src/legacy/kernels/mod.rs index 86db1c7e10b6..b8676430ec52 100644 --- a/crates/polars-arrow/src/legacy/kernels/mod.rs +++ b/crates/polars-arrow/src/legacy/kernels/mod.rs @@ -59,8 +59,7 @@ impl<'a> MaskedSlicesIterator<'a> { pub(crate) fn new(mask: &'a BooleanArray) -> Self { let chunks = mask.values().chunks::(); - let chunk_bits = 8 * std::mem::size_of::(); - let chunk_len = mask.len() / chunk_bits; + let chunk_len = mask.len() / 64; let remainder_len = chunks.remainder_len(); let remainder_mask = chunks.remainder(); diff --git a/crates/polars-arrow/src/mmap/array.rs b/crates/polars-arrow/src/mmap/array.rs index 8822824858c6..060ab745fcc0 100644 --- a/crates/polars-arrow/src/mmap/array.rs +++ b/crates/polars-arrow/src/mmap/array.rs @@ -35,7 +35,7 @@ fn check_bytes_len_and_is_aligned( bytes: &[u8], expected_len: usize, ) -> PolarsResult { - if bytes.len() < std::mem::size_of::() * expected_len { + if bytes.len() < size_of::() * expected_len { polars_bail!(ComputeError: "buffer's length is too small in mmap") }; @@ -281,7 +281,7 @@ fn mmap_primitive>( let bytes = get_bytes(data_ref, block_offset, buffers)?; let is_aligned = check_bytes_len_and_is_aligned::

(bytes, num_rows)?; - let out = if is_aligned || std::mem::size_of::() <= 8 { + let out = if is_aligned || size_of::() <= 8 { assert!( is_aligned, "primitive type with size <= 8 bytes should have been aligned" diff --git a/crates/polars-arrow/src/storage.rs b/crates/polars-arrow/src/storage.rs index 7cab3235b25a..a193fd519a38 100644 --- a/crates/polars-arrow/src/storage.rs +++ b/crates/polars-arrow/src/storage.rs @@ -100,9 +100,9 @@ impl SharedStorage { impl SharedStorage { pub fn from_arrow_buffer(buffer: arrow_buffer::Buffer) -> Self { let ptr = buffer.as_ptr(); - let align_offset = ptr.align_offset(std::mem::align_of::()); + let align_offset = ptr.align_offset(align_of::()); assert_eq!(align_offset, 0, "arrow_buffer::Buffer misaligned"); - let length = buffer.len() / std::mem::size_of::(); + let length = buffer.len() / size_of::(); let inner = SharedStorageInner { ref_count: AtomicU64::new(1), @@ -119,7 +119,7 @@ impl SharedStorage { pub fn into_arrow_buffer(self) -> arrow_buffer::Buffer { let ptr = NonNull::new(self.as_ptr() as *mut u8).unwrap(); - let len = self.len() * std::mem::size_of::(); + let len = self.len() * size_of::(); let arc = std::sync::Arc::new(self); unsafe { arrow_buffer::Buffer::from_custom_allocation(ptr, len, arc) } } diff --git a/crates/polars-arrow/src/types/bit_chunk.rs b/crates/polars-arrow/src/types/bit_chunk.rs index be4445a5d77a..60892689060f 100644 --- a/crates/polars-arrow/src/types/bit_chunk.rs +++ b/crates/polars-arrow/src/types/bit_chunk.rs @@ -72,7 +72,7 @@ impl BitChunkIter { /// Creates a new [`BitChunkIter`] with `len` bits. #[inline] pub fn new(value: T, len: usize) -> Self { - assert!(len <= std::mem::size_of::() * 8); + assert!(len <= size_of::() * 8); Self { value, remaining: len, diff --git a/crates/polars-arrow/src/types/native.rs b/crates/polars-arrow/src/types/native.rs index 230fdde387d1..12d512f844c5 100644 --- a/crates/polars-arrow/src/types/native.rs +++ b/crates/polars-arrow/src/types/native.rs @@ -60,7 +60,7 @@ macro_rules! native_type { impl NativeType for $type { const PRIMITIVE: PrimitiveType = $primitive_type; - type Bytes = [u8; std::mem::size_of::()]; + type Bytes = [u8; size_of::()]; #[inline] fn to_le_bytes(&self) -> Self::Bytes { Self::to_le_bytes(*self) diff --git a/crates/polars-compute/src/arity.rs b/crates/polars-compute/src/arity.rs index 33c8b0eb0584..7f99752e7afe 100644 --- a/crates/polars-compute/src/arity.rs +++ b/crates/polars-compute/src/arity.rs @@ -52,9 +52,7 @@ where let len = arr.len(); // Reuse memory if possible. - if std::mem::size_of::() == std::mem::size_of::() - && std::mem::align_of::() == std::mem::align_of::() - { + if size_of::() == size_of::() && align_of::() == align_of::() { if let Some(values) = arr.get_mut_values() { let ptr = values.as_mut_ptr(); // SAFETY: checked same size & alignment I/O, NativeType is always Pod. @@ -93,9 +91,7 @@ where let validity = combine_validities_and(lhs.validity(), rhs.validity()); // Reuse memory if possible. - if std::mem::size_of::() == std::mem::size_of::() - && std::mem::align_of::() == std::mem::align_of::() - { + if size_of::() == size_of::() && align_of::() == align_of::() { if let Some(lv) = lhs.get_mut_values() { let lp = lv.as_mut_ptr(); let rp = rhs.values().as_ptr(); @@ -106,9 +102,7 @@ where return lhs.transmute::().with_validity(validity); } } - if std::mem::size_of::() == std::mem::size_of::() - && std::mem::align_of::() == std::mem::align_of::() - { + if size_of::() == size_of::() && align_of::() == align_of::() { if let Some(rv) = rhs.get_mut_values() { let lp = lhs.values().as_ptr(); let rp = rv.as_mut_ptr(); diff --git a/crates/polars-compute/src/comparisons/simd.rs b/crates/polars-compute/src/comparisons/simd.rs index f855ed4ad1c0..95ea9707744a 100644 --- a/crates/polars-compute/src/comparisons/simd.rs +++ b/crates/polars-compute/src/comparisons/simd.rs @@ -17,7 +17,7 @@ where T: NativeType, F: FnMut(&[T; N], &[T; N]) -> M, { - assert_eq!(N, std::mem::size_of::() * 8); + assert_eq!(N, size_of::() * 8); assert!(lhs.len() == rhs.len()); let n = lhs.len(); @@ -29,7 +29,7 @@ where let rhs_rest = rhs_chunks.remainder(); let num_masks = n.div_ceil(N); - let mut v: Vec = Vec::with_capacity(num_masks * std::mem::size_of::()); + let mut v: Vec = Vec::with_capacity(num_masks * size_of::()); let mut p = v.as_mut_ptr() as *mut M; for (l, r) in lhs_chunks.zip(rhs_chunks) { unsafe { @@ -53,7 +53,7 @@ where } unsafe { - v.set_len(num_masks * std::mem::size_of::()); + v.set_len(num_masks * size_of::()); } Bitmap::from_u8_vec(v, n) @@ -64,7 +64,7 @@ where T: NativeType, F: FnMut(&[T; N]) -> M, { - assert_eq!(N, std::mem::size_of::() * 8); + assert_eq!(N, size_of::() * 8); let n = arg.len(); let arg_buf = arg.values().as_slice(); @@ -72,7 +72,7 @@ where let arg_rest = arg_chunks.remainder(); let num_masks = n.div_ceil(N); - let mut v: Vec = Vec::with_capacity(num_masks * std::mem::size_of::()); + let mut v: Vec = Vec::with_capacity(num_masks * size_of::()); let mut p = v.as_mut_ptr() as *mut M; for a in arg_chunks { unsafe { @@ -91,7 +91,7 @@ where } unsafe { - v.set_len(num_masks * std::mem::size_of::()); + v.set_len(num_masks * size_of::()); } Bitmap::from_u8_vec(v, n) diff --git a/crates/polars-compute/src/filter/avx512.rs b/crates/polars-compute/src/filter/avx512.rs index 11466b137be8..237aed8ed483 100644 --- a/crates/polars-compute/src/filter/avx512.rs +++ b/crates/polars-compute/src/filter/avx512.rs @@ -5,7 +5,7 @@ use core::arch::x86_64::*; // structured functions. macro_rules! simd_filter { ($values: ident, $mask_bytes: ident, $out: ident, |$subchunk: ident, $m: ident: $MaskT: ty| $body:block) => {{ - const MASK_BITS: usize = std::mem::size_of::<$MaskT>() * 8; + const MASK_BITS: usize = <$MaskT>::BITS as usize; // Do a 64-element loop for sparse fast path. let chunks = $values.chunks_exact(64); diff --git a/crates/polars-compute/src/filter/primitive.rs b/crates/polars-compute/src/filter/primitive.rs index 9cc542b60978..4671fa4ff592 100644 --- a/crates/polars-compute/src/filter/primitive.rs +++ b/crates/polars-compute/src/filter/primitive.rs @@ -19,7 +19,7 @@ fn nop_filter<'a, T: Pod>( } pub fn filter_values(values: &[T], mask: &Bitmap) -> Vec { - match (std::mem::size_of::(), std::mem::align_of::()) { + match (size_of::(), align_of::()) { (1, 1) => cast_vec(filter_values_u8(cast_slice(values), mask)), (2, 2) => cast_vec(filter_values_u16(cast_slice(values), mask)), (4, 4) => cast_vec(filter_values_u32(cast_slice(values), mask)), diff --git a/crates/polars-core/src/chunked_array/object/builder.rs b/crates/polars-core/src/chunked_array/object/builder.rs index 45f63847e97f..9383634cdcac 100644 --- a/crates/polars-core/src/chunked_array/object/builder.rs +++ b/crates/polars-core/src/chunked_array/object/builder.rs @@ -80,7 +80,7 @@ pub(crate) fn get_object_type() -> DataType { Box::new(ObjectChunkedBuilder::::new(name, capacity)) as Box }); - let object_size = std::mem::size_of::(); + let object_size = size_of::(); let physical_dtype = ArrowDataType::FixedSizeBinary(object_size); let registry = ObjectRegistry::new(object_builder, physical_dtype); diff --git a/crates/polars-core/src/chunked_array/object/extension/mod.rs b/crates/polars-core/src/chunked_array/object/extension/mod.rs index 89ccd65a7c1a..f9167b200211 100644 --- a/crates/polars-core/src/chunked_array/object/extension/mod.rs +++ b/crates/polars-core/src/chunked_array/object/extension/mod.rs @@ -29,7 +29,7 @@ pub fn set_polars_allow_extension(toggle: bool) { /// `n_t_vals` must represent the correct number of `T` values in that allocation unsafe fn create_drop(mut ptr: *const u8, n_t_vals: usize) -> Box { Box::new(move || { - let t_size = std::mem::size_of::() as isize; + let t_size = size_of::() as isize; for _ in 0..n_t_vals { let _ = std::ptr::read_unaligned(ptr as *const T); ptr = ptr.offset(t_size) @@ -55,7 +55,7 @@ impl Drop for ExtensionSentinel { // https://stackoverflow.com/questions/28127165/how-to-convert-struct-to-u8d // not entirely sure if padding bytes in T are initialized or not. unsafe fn any_as_u8_slice(p: &T) -> &[u8] { - std::slice::from_raw_parts((p as *const T) as *const u8, std::mem::size_of::()) + std::slice::from_raw_parts((p as *const T) as *const u8, size_of::()) } /// Create an extension Array that can be sent to arrow and (once wrapped in `[PolarsExtension]` will @@ -67,8 +67,8 @@ pub(crate) fn create_extension> + TrustedLen, T: Si if !(POLARS_ALLOW_EXTENSION.load(Ordering::Relaxed) || std::env::var(env).is_ok()) { panic!("creating extension types not allowed - try setting the environment variable {env}") } - let t_size = std::mem::size_of::(); - let t_alignment = std::mem::align_of::(); + let t_size = size_of::(); + let t_alignment = align_of::(); let n_t_vals = iter.size_hint().1.unwrap(); let mut buf = Vec::with_capacity(n_t_vals * t_size); diff --git a/crates/polars-core/src/chunked_array/object/mod.rs b/crates/polars-core/src/chunked_array/object/mod.rs index a7e3d2f9952d..8f4711976856 100644 --- a/crates/polars-core/src/chunked_array/object/mod.rs +++ b/crates/polars-core/src/chunked_array/object/mod.rs @@ -164,7 +164,7 @@ where } fn dtype(&self) -> &ArrowDataType { - &ArrowDataType::FixedSizeBinary(std::mem::size_of::()) + &ArrowDataType::FixedSizeBinary(size_of::()) } fn slice(&mut self, offset: usize, length: usize) { @@ -275,7 +275,7 @@ impl StaticArray for ObjectArray { impl ParameterFreeDtypeStaticArray for ObjectArray { fn get_dtype() -> ArrowDataType { - ArrowDataType::FixedSizeBinary(std::mem::size_of::()) + ArrowDataType::FixedSizeBinary(size_of::()) } } diff --git a/crates/polars-core/src/chunked_array/ops/bit_repr.rs b/crates/polars-core/src/chunked_array/ops/bit_repr.rs index 7b20d77e2444..7236fde9993c 100644 --- a/crates/polars-core/src/chunked_array/ops/bit_repr.rs +++ b/crates/polars-core/src/chunked_array/ops/bit_repr.rs @@ -8,8 +8,8 @@ use crate::series::BitRepr; fn reinterpret_chunked_array( ca: &ChunkedArray, ) -> ChunkedArray { - assert!(std::mem::size_of::() == std::mem::size_of::()); - assert!(std::mem::align_of::() == std::mem::align_of::()); + assert!(size_of::() == size_of::()); + assert!(align_of::() == align_of::()); let chunks = ca.downcast_iter().map(|array| { let buf = array.values().clone(); @@ -29,8 +29,8 @@ fn reinterpret_chunked_array( fn reinterpret_list_chunked( ca: &ListChunked, ) -> ListChunked { - assert!(std::mem::size_of::() == std::mem::size_of::()); - assert!(std::mem::align_of::() == std::mem::align_of::()); + assert!(size_of::() == size_of::()); + assert!(align_of::() == align_of::()); let chunks = ca.downcast_iter().map(|array| { let inner_arr = array @@ -105,7 +105,7 @@ where T: PolarsNumericType, { fn to_bit_repr(&self) -> BitRepr { - let is_large = std::mem::size_of::() == 8; + let is_large = size_of::() == 8; if is_large { if matches!(self.dtype(), DataType::UInt64) { @@ -118,7 +118,7 @@ where BitRepr::Large(reinterpret_chunked_array(self)) } else { - BitRepr::Small(if std::mem::size_of::() == 4 { + BitRepr::Small(if size_of::() == 4 { if matches!(self.dtype(), DataType::UInt32) { let ca = self.clone(); // Convince the compiler we are this type. This preserves flags. diff --git a/crates/polars-core/src/frame/group_by/perfect.rs b/crates/polars-core/src/frame/group_by/perfect.rs index 86d952828c85..da4e4014b31c 100644 --- a/crates/polars-core/src/frame/group_by/perfect.rs +++ b/crates/polars-core/src/frame/group_by/perfect.rs @@ -44,8 +44,8 @@ where let mut first: Vec = unsafe { aligned_vec(len) }; // ensure we keep aligned to cache lines - let chunk_size = (chunk_size * std::mem::size_of::()).next_multiple_of(64); - let chunk_size = chunk_size / std::mem::size_of::(); + let chunk_size = (chunk_size * size_of::()).next_multiple_of(64); + let chunk_size = chunk_size / size_of::(); let mut cache_line_offsets = Vec::with_capacity(n_threads + 1); cache_line_offsets.push(0); @@ -227,8 +227,8 @@ struct AlignTo64([u8; 64]); /// There are no guarantees that the [`Vec`] will remain aligned if you reallocate the data. /// This means that you cannot reallocate so you will need to know how big to allocate up front. unsafe fn aligned_vec(n: usize) -> Vec { - assert!(std::mem::align_of::() <= 64); - let n_units = (n * std::mem::size_of::() / std::mem::size_of::()) + 1; + assert!(align_of::() <= 64); + let n_units = (n * size_of::() / size_of::()) + 1; let mut aligned: Vec = Vec::with_capacity(n_units); @@ -240,6 +240,6 @@ unsafe fn aligned_vec(n: usize) -> Vec { Vec::from_raw_parts( ptr as *mut T, 0, - cap_units * std::mem::size_of::() / std::mem::size_of::(), + cap_units * size_of::() / size_of::(), ) } diff --git a/crates/polars-core/src/series/mod.rs b/crates/polars-core/src/series/mod.rs index 35f5b1258b19..8ad018a4a678 100644 --- a/crates/polars-core/src/series/mod.rs +++ b/crates/polars-core/src/series/mod.rs @@ -873,8 +873,7 @@ impl Series { DataType::Categorical(Some(rv), _) | DataType::Enum(Some(rv), _) => match &**rv { RevMapping::Local(arr, _) => size += estimated_bytes_size(arr), RevMapping::Global(map, arr, _) => { - size += - map.capacity() * std::mem::size_of::() * 2 + estimated_bytes_size(arr); + size += map.capacity() * size_of::() * 2 + estimated_bytes_size(arr); }, }, _ => {}, diff --git a/crates/polars-core/src/utils/mod.rs b/crates/polars-core/src/utils/mod.rs index 169c30fd0498..05171fe35cfe 100644 --- a/crates/polars-core/src/utils/mod.rs +++ b/crates/polars-core/src/utils/mod.rs @@ -1159,7 +1159,7 @@ pub fn coalesce_nulls_columns(a: &Column, b: &Column) -> (Column, Column) { } pub fn operation_exceeded_idxsize_msg(operation: &str) -> String { - if core::mem::size_of::() == core::mem::size_of::() { + if size_of::() == size_of::() { format!( "{} exceeded the maximum supported limit of {} rows. Consider installing 'polars-u64-idx'.", operation, diff --git a/crates/polars-ops/src/chunked_array/strings/case.rs b/crates/polars-ops/src/chunked_array/strings/case.rs index 7bb348e28803..4004f122143f 100644 --- a/crates/polars-ops/src/chunked_array/strings/case.rs +++ b/crates/polars-ops/src/chunked_array/strings/case.rs @@ -5,7 +5,7 @@ fn convert_while_ascii(b: &[u8], convert: fn(&u8) -> u8, out: &mut Vec) { out.clear(); out.reserve(b.len()); - const USIZE_SIZE: usize = std::mem::size_of::(); + const USIZE_SIZE: usize = size_of::(); const MAGIC_UNROLL: usize = 2; const N: usize = USIZE_SIZE * MAGIC_UNROLL; const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; USIZE_SIZE]); diff --git a/crates/polars-parquet/src/arrow/read/deserialize/primitive/float.rs b/crates/polars-parquet/src/arrow/read/deserialize/primitive/float.rs index 0a43141abd06..eb4815b6fbfe 100644 --- a/crates/polars-parquet/src/arrow/read/deserialize/primitive/float.rs +++ b/crates/polars-parquet/src/arrow/read/deserialize/primitive/float.rs @@ -55,7 +55,7 @@ where let values = split_buffer(page)?.values; Ok(Self::ByteStreamSplit(byte_stream_split::Decoder::try_new( values, - std::mem::size_of::

(), + size_of::

(), )?)) }, _ => Err(utils::not_implemented(page)), diff --git a/crates/polars-parquet/src/arrow/read/deserialize/primitive/integer.rs b/crates/polars-parquet/src/arrow/read/deserialize/primitive/integer.rs index ed8e0a541a68..ff9c0b014b08 100644 --- a/crates/polars-parquet/src/arrow/read/deserialize/primitive/integer.rs +++ b/crates/polars-parquet/src/arrow/read/deserialize/primitive/integer.rs @@ -58,7 +58,7 @@ where let values = split_buffer(page)?.values; Ok(Self::ByteStreamSplit(byte_stream_split::Decoder::try_new( values, - std::mem::size_of::

(), + size_of::

(), )?)) }, (Encoding::DeltaBinaryPacked, _) => { diff --git a/crates/polars-parquet/src/arrow/read/deserialize/primitive/mod.rs b/crates/polars-parquet/src/arrow/read/deserialize/primitive/mod.rs index 1a9d50a66d31..54ed87c6b42b 100644 --- a/crates/polars-parquet/src/arrow/read/deserialize/primitive/mod.rs +++ b/crates/polars-parquet/src/arrow/read/deserialize/primitive/mod.rs @@ -167,7 +167,7 @@ where D: DecoderFunction, { values - .chunks_exact(std::mem::size_of::

()) + .chunks_exact(size_of::

()) .map(decode) .map(|v| decoder.decode(v)) .collect::>() diff --git a/crates/polars-parquet/src/arrow/read/deserialize/utils/array_chunks.rs b/crates/polars-parquet/src/arrow/read/deserialize/utils/array_chunks.rs index 330ad77a7c44..0882cbed5cb0 100644 --- a/crates/polars-parquet/src/arrow/read/deserialize/utils/array_chunks.rs +++ b/crates/polars-parquet/src/arrow/read/deserialize/utils/array_chunks.rs @@ -16,7 +16,7 @@ impl<'a, P: ParquetNativeType> ArrayChunks<'a, P> { /// /// This returns null if the `bytes` slice's length is not a multiple of the size of `P::Bytes`. pub(crate) fn new(bytes: &'a [u8]) -> Option { - if bytes.len() % std::mem::size_of::() != 0 { + if bytes.len() % size_of::() != 0 { return None; } diff --git a/crates/polars-parquet/src/arrow/write/binary/basic.rs b/crates/polars-parquet/src/arrow/write/binary/basic.rs index 0032a5d1e29d..7af6ab5f353d 100644 --- a/crates/polars-parquet/src/arrow/write/binary/basic.rs +++ b/crates/polars-parquet/src/arrow/write/binary/basic.rs @@ -30,15 +30,15 @@ pub(crate) fn encode_plain( ) { if options.is_optional() && array.validity().is_some() { let len_before = buffer.len(); - let capacity = array.get_values_size() - + (array.len() - array.null_count()) * std::mem::size_of::(); + let capacity = + array.get_values_size() + (array.len() - array.null_count()) * size_of::(); buffer.reserve(capacity); encode_non_null_values(array.non_null_values_iter(), buffer); // Ensure we allocated properly. debug_assert_eq!(buffer.len() - len_before, capacity); } else { let len_before = buffer.len(); - let capacity = array.get_values_size() + array.len() * std::mem::size_of::(); + let capacity = array.get_values_size() + array.len() * size_of::(); buffer.reserve(capacity); encode_non_null_values(array.values_iter(), buffer); // Ensure we allocated properly. diff --git a/crates/polars-parquet/src/arrow/write/binview/basic.rs b/crates/polars-parquet/src/arrow/write/binview/basic.rs index 8251818e722f..018e1627d25f 100644 --- a/crates/polars-parquet/src/arrow/write/binview/basic.rs +++ b/crates/polars-parquet/src/arrow/write/binview/basic.rs @@ -16,8 +16,8 @@ pub(crate) fn encode_plain( buffer: &mut Vec, ) { if options.is_optional() && array.validity().is_some() { - let capacity = array.total_bytes_len() - + (array.len() - array.null_count()) * std::mem::size_of::(); + let capacity = + array.total_bytes_len() + (array.len() - array.null_count()) * size_of::(); let len_before = buffer.len(); buffer.reserve(capacity); @@ -26,7 +26,7 @@ pub(crate) fn encode_plain( // Append the non-null values. debug_assert_eq!(buffer.len() - len_before, capacity); } else { - let capacity = array.total_bytes_len() + array.len() * std::mem::size_of::(); + let capacity = array.total_bytes_len() + array.len() * size_of::(); let len_before = buffer.len(); buffer.reserve(capacity); diff --git a/crates/polars-parquet/src/arrow/write/primitive/basic.rs b/crates/polars-parquet/src/arrow/write/primitive/basic.rs index d970e3659dcb..88bab6ca5ea6 100644 --- a/crates/polars-parquet/src/arrow/write/primitive/basic.rs +++ b/crates/polars-parquet/src/arrow/write/primitive/basic.rs @@ -38,7 +38,7 @@ where let mut iter = validity.iter(); let values = array.values().as_slice(); - buffer.reserve(std::mem::size_of::() * (array.len() - null_count)); + buffer.reserve(size_of::() * (array.len() - null_count)); let mut offset = 0; let mut remaining_valid = array.len() - null_count; @@ -61,7 +61,7 @@ where } } - buffer.reserve(std::mem::size_of::

() * array.len()); + buffer.reserve(size_of::

() * array.len()); buffer.extend( array .values() diff --git a/crates/polars-parquet/src/parquet/compression.rs b/crates/polars-parquet/src/parquet/compression.rs index 41bfb5f557bf..f8e90f65e3ee 100644 --- a/crates/polars-parquet/src/parquet/compression.rs +++ b/crates/polars-parquet/src/parquet/compression.rs @@ -245,7 +245,7 @@ fn try_decompress_hadoop(input_buf: &[u8], output_buf: &mut [u8]) -> ParquetResu // The Hadoop Lz4Codec source code can be found here: // https://github.com/apache/hadoop/blob/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-nativetask/src/main/native/src/codec/Lz4Codec.cc - const SIZE_U32: usize = std::mem::size_of::(); + const SIZE_U32: usize = size_of::(); const PREFIX_LEN: usize = SIZE_U32 * 2; let mut input_len = input_buf.len(); let mut input = input_buf; diff --git a/crates/polars-parquet/src/parquet/encoding/bitpacked/decode.rs b/crates/polars-parquet/src/parquet/encoding/bitpacked/decode.rs index 6e37507d137f..b453c7b6e0f6 100644 --- a/crates/polars-parquet/src/parquet/encoding/bitpacked/decode.rs +++ b/crates/polars-parquet/src/parquet/encoding/bitpacked/decode.rs @@ -56,7 +56,7 @@ impl<'a, T: Unpackable> Decoder<'a, T> { num_bits: usize, length: usize, ) -> ParquetResult { - let block_size = std::mem::size_of::() * num_bits; + let block_size = size_of::() * num_bits; if packed.len() * 8 < length * num_bits { return Err(ParquetError::oos(format!( @@ -78,7 +78,7 @@ impl<'a, T: Unpackable> Decoder<'a, T> { /// Returns a [`Decoder`] with `T` encoded in `packed` with `num_bits`. pub fn try_new(packed: &'a [u8], num_bits: usize, length: usize) -> ParquetResult { - let block_size = std::mem::size_of::() * num_bits; + let block_size = size_of::() * num_bits; if num_bits == 0 { return Err(ParquetError::oos("Bitpacking requires num_bits > 0")); @@ -181,7 +181,7 @@ impl<'a, T: Unpackable> Decoder<'a, T> { } pub fn take(&mut self) -> Self { - let block_size = std::mem::size_of::() * self.num_bits; + let block_size = size_of::() * self.num_bits; let packed = std::mem::replace(&mut self.packed, [].chunks(block_size)); let length = self.length; self.length = 0; diff --git a/crates/polars-parquet/src/parquet/encoding/byte_stream_split/mod.rs b/crates/polars-parquet/src/parquet/encoding/byte_stream_split/mod.rs index 1ef6a99a2128..555954ff8069 100644 --- a/crates/polars-parquet/src/parquet/encoding/byte_stream_split/mod.rs +++ b/crates/polars-parquet/src/parquet/encoding/byte_stream_split/mod.rs @@ -14,7 +14,7 @@ mod tests { let mut buffer = vec![]; encode(&data, &mut buffer); - let mut decoder = Decoder::try_new(&buffer, std::mem::size_of::())?; + let mut decoder = Decoder::try_new(&buffer, size_of::())?; let values = decoder .iter_converted(|bytes| f32::from_le_bytes(bytes.try_into().unwrap())) .collect::>(); @@ -30,7 +30,7 @@ mod tests { let mut buffer = vec![]; encode(&data, &mut buffer); - let mut decoder = Decoder::try_new(&buffer, std::mem::size_of::())?; + let mut decoder = Decoder::try_new(&buffer, size_of::())?; let values = decoder .iter_converted(|bytes| f64::from_le_bytes(bytes.try_into().unwrap())) .collect::>(); @@ -61,9 +61,9 @@ mod tests { } fn encode(data: &[T], buffer: &mut Vec) { - let element_size = std::mem::size_of::(); + let element_size = size_of::(); let num_elements = data.len(); - let total_length = std::mem::size_of_val(data); + let total_length = size_of_val(data); buffer.resize(total_length, 0); for (i, v) in data.iter().enumerate() { diff --git a/crates/polars-parquet/src/parquet/encoding/hybrid_rle/mod.rs b/crates/polars-parquet/src/parquet/encoding/hybrid_rle/mod.rs index c71b6455ddf4..f721274d00cd 100644 --- a/crates/polars-parquet/src/parquet/encoding/hybrid_rle/mod.rs +++ b/crates/polars-parquet/src/parquet/encoding/hybrid_rle/mod.rs @@ -133,7 +133,7 @@ impl<'a> HybridRleDecoder<'a> { if run_length == 0 { 0 } else { - let mut bytes = [0u8; std::mem::size_of::()]; + let mut bytes = [0u8; size_of::()]; pack.iter().zip(bytes.iter_mut()).for_each(|(src, dst)| { *dst = *src; }); @@ -380,7 +380,7 @@ impl<'a> HybridRleDecoder<'a> { if run_length <= n { run_length } else { - let mut bytes = [0u8; std::mem::size_of::()]; + let mut bytes = [0u8; size_of::()]; pack.iter().zip(bytes.iter_mut()).for_each(|(src, dst)| { *dst = *src; }); diff --git a/crates/polars-parquet/src/parquet/statistics/boolean.rs b/crates/polars-parquet/src/parquet/statistics/boolean.rs index b171a2efdd51..55e478d5b957 100644 --- a/crates/polars-parquet/src/parquet/statistics/boolean.rs +++ b/crates/polars-parquet/src/parquet/statistics/boolean.rs @@ -13,14 +13,14 @@ pub struct BooleanStatistics { impl BooleanStatistics { pub fn deserialize(v: &ParquetStatistics) -> ParquetResult { if let Some(ref v) = v.max_value { - if v.len() != std::mem::size_of::() { + if v.len() != size_of::() { return Err(ParquetError::oos( "The max_value of statistics MUST be plain encoded", )); } }; if let Some(ref v) = v.min_value { - if v.len() != std::mem::size_of::() { + if v.len() != size_of::() { return Err(ParquetError::oos( "The min_value of statistics MUST be plain encoded", )); diff --git a/crates/polars-parquet/src/parquet/statistics/primitive.rs b/crates/polars-parquet/src/parquet/statistics/primitive.rs index c4cd417b635c..7bd8d227faa2 100644 --- a/crates/polars-parquet/src/parquet/statistics/primitive.rs +++ b/crates/polars-parquet/src/parquet/statistics/primitive.rs @@ -20,7 +20,7 @@ impl PrimitiveStatistics { ) -> ParquetResult { if v.max_value .as_ref() - .is_some_and(|v| v.len() != std::mem::size_of::()) + .is_some_and(|v| v.len() != size_of::()) { return Err(ParquetError::oos( "The max_value of statistics MUST be plain encoded", @@ -28,7 +28,7 @@ impl PrimitiveStatistics { }; if v.min_value .as_ref() - .is_some_and(|v| v.len() != std::mem::size_of::()) + .is_some_and(|v| v.len() != size_of::()) { return Err(ParquetError::oos( "The min_value of statistics MUST be plain encoded", diff --git a/crates/polars-parquet/src/parquet/types.rs b/crates/polars-parquet/src/parquet/types.rs index 7591f6ba0bd7..1dd65d0ff622 100644 --- a/crates/polars-parquet/src/parquet/types.rs +++ b/crates/polars-parquet/src/parquet/types.rs @@ -22,7 +22,7 @@ pub trait NativeType: std::fmt::Debug + Send + Sync + 'static + Copy + Clone { macro_rules! native { ($type:ty, $physical_type:expr) => { impl NativeType for $type { - type Bytes = [u8; std::mem::size_of::()]; + type Bytes = [u8; size_of::()]; #[inline] fn to_le_bytes(&self) -> Self::Bytes { Self::to_le_bytes(*self) @@ -51,7 +51,7 @@ native!(f64, PhysicalType::Double); impl NativeType for [u32; 3] { const TYPE: PhysicalType = PhysicalType::Int96; - type Bytes = [u8; std::mem::size_of::()]; + type Bytes = [u8; size_of::()]; #[inline] fn to_le_bytes(&self) -> Self::Bytes { let mut bytes = [0; 12]; @@ -137,7 +137,7 @@ pub fn ord_binary<'a>(a: &'a [u8], b: &'a [u8]) -> std::cmp::Ordering { #[inline] pub fn decode(chunk: &[u8]) -> T { - assert!(chunk.len() >= std::mem::size_of::<::Bytes>()); + assert!(chunk.len() >= size_of::<::Bytes>()); unsafe { decode_unchecked(chunk) } } diff --git a/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs b/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs index e6711b7a339b..14ce4836096c 100644 --- a/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs +++ b/crates/polars-pipe/src/executors/sinks/group_by/aggregates/convert.rs @@ -208,7 +208,7 @@ where let agg_fn = match logical_dtype.to_physical() { // Boolean is aggregated as the IDX type. DataType::Boolean => { - if std::mem::size_of::() == 4 { + if size_of::() == 4 { AggregateFunction::SumU32(SumAgg::::new()) } else { AggregateFunction::SumU64(SumAgg::::new()) diff --git a/crates/polars-plan/src/plans/ir/mod.rs b/crates/polars-plan/src/plans/ir/mod.rs index a9eb45b6406f..14b658bea22f 100644 --- a/crates/polars-plan/src/plans/ir/mod.rs +++ b/crates/polars-plan/src/plans/ir/mod.rs @@ -272,6 +272,6 @@ mod test { #[ignore] #[test] fn test_alp_size() { - assert!(std::mem::size_of::() <= 152); + assert!(size_of::() <= 152); } } diff --git a/crates/polars-python/src/conversion/any_value.rs b/crates/polars-python/src/conversion/any_value.rs index 712e0817e5b7..eb4835ada90f 100644 --- a/crates/polars-python/src/conversion/any_value.rs +++ b/crates/polars-python/src/conversion/any_value.rs @@ -115,7 +115,7 @@ pub(crate) fn any_value_into_py_object(av: AnyValue, py: Python) -> PyObject { let buf = unsafe { std::slice::from_raw_parts( buf.as_slice().as_ptr() as *const u8, - N * std::mem::size_of::(), + N * size_of::(), ) }; let digits = PyTuple::new_bound(py, buf.iter().take(n_digits)); diff --git a/crates/polars-python/src/conversion/chunked_array.rs b/crates/polars-python/src/conversion/chunked_array.rs index 3a69d61f7dd1..404fe68ce8ef 100644 --- a/crates/polars-python/src/conversion/chunked_array.rs +++ b/crates/polars-python/src/conversion/chunked_array.rs @@ -127,7 +127,7 @@ pub(crate) fn decimal_to_pyobject_iter<'a>( let buf = unsafe { std::slice::from_raw_parts( buf.as_slice().as_ptr() as *const u8, - N * std::mem::size_of::(), + N * size_of::(), ) }; let digits = PyTuple::new_bound(py, buf.iter().take(n_digits)); diff --git a/crates/polars-python/src/conversion/mod.rs b/crates/polars-python/src/conversion/mod.rs index 26bd02c6e540..ac3286aaab36 100644 --- a/crates/polars-python/src/conversion/mod.rs +++ b/crates/polars-python/src/conversion/mod.rs @@ -59,8 +59,8 @@ unsafe impl Transparent for Option { } pub(crate) fn reinterpret_vec(input: Vec) -> Vec { - assert_eq!(std::mem::size_of::(), std::mem::size_of::()); - assert_eq!(std::mem::align_of::(), std::mem::align_of::()); + assert_eq!(size_of::(), size_of::()); + assert_eq!(align_of::(), align_of::()); let len = input.len(); let cap = input.capacity(); let mut manual_drop_vec = std::mem::ManuallyDrop::new(input); diff --git a/crates/polars-python/src/on_startup.rs b/crates/polars-python/src/on_startup.rs index 9b6f17d46f72..8c0b4275b4ba 100644 --- a/crates/polars-python/src/on_startup.rs +++ b/crates/polars-python/src/on_startup.rs @@ -88,7 +88,7 @@ pub fn register_startup_deps() { Box::new(object) as Box }); - let object_size = std::mem::size_of::(); + let object_size = size_of::(); let physical_dtype = ArrowDataType::FixedSizeBinary(object_size); registry::register_object_builder(object_builder, object_converter, physical_dtype); // register SERIES UDF diff --git a/crates/polars-python/src/series/numpy_ufunc.rs b/crates/polars-python/src/series/numpy_ufunc.rs index 10d765c3fc25..5df438686447 100644 --- a/crates/polars-python/src/series/numpy_ufunc.rs +++ b/crates/polars-python/src/series/numpy_ufunc.rs @@ -1,4 +1,4 @@ -use std::{mem, ptr}; +use std::ptr; use ndarray::IntoDimension; use numpy::npyffi::types::npy_intp; @@ -30,7 +30,7 @@ unsafe fn aligned_array( let buffer_ptr = buf.as_mut_ptr(); let mut dims = [len].into_dimension(); - let strides = [mem::size_of::() as npy_intp]; + let strides = [size_of::() as npy_intp]; let ptr = PY_ARRAY_API.PyArray_NewFromDescr( py, diff --git a/crates/polars-row/src/fixed.rs b/crates/polars-row/src/fixed.rs index 7932420d1577..89f904e54296 100644 --- a/crates/polars-row/src/fixed.rs +++ b/crates/polars-row/src/fixed.rs @@ -25,7 +25,7 @@ impl FromSlice for [u8; N] { pub trait FixedLengthEncoding: Copy + Debug { // 1 is validity 0 or 1 // bit repr of encoding - const ENCODED_LEN: usize = 1 + std::mem::size_of::(); + const ENCODED_LEN: usize = 1 + size_of::(); type Encoded: Sized + Copy + AsRef<[u8]> + AsMut<[u8]>; diff --git a/crates/polars-row/src/row.rs b/crates/polars-row/src/row.rs index d48f6f51c205..1aa50e8b0e43 100644 --- a/crates/polars-row/src/row.rs +++ b/crates/polars-row/src/row.rs @@ -40,8 +40,8 @@ pub struct RowsEncoded { fn checks(offsets: &[usize]) { assert_eq!( - std::mem::size_of::(), - std::mem::size_of::(), + size_of::(), + size_of::(), "only supported on 64bit arch" ); assert!( diff --git a/crates/polars-utils/src/arena.rs b/crates/polars-utils/src/arena.rs index c8b5823d695e..270a3fb9b835 100644 --- a/crates/polars-utils/src/arena.rs +++ b/crates/polars-utils/src/arena.rs @@ -7,11 +7,11 @@ use crate::error::*; use crate::slice::GetSaferUnchecked; unsafe fn index_of_unchecked(slice: &[T], item: &T) -> usize { - (item as *const _ as usize - slice.as_ptr() as usize) / std::mem::size_of::() + (item as *const _ as usize - slice.as_ptr() as usize) / size_of::() } fn index_of(slice: &[T], item: &T) -> Option { - debug_assert!(std::mem::size_of::() > 0); + debug_assert!(size_of::() > 0); let ptr = item as *const T; unsafe { if slice.as_ptr() < ptr && slice.as_ptr().add(slice.len()) > ptr { diff --git a/crates/polars-utils/src/idx_vec.rs b/crates/polars-utils/src/idx_vec.rs index 8bfdfafa2fd4..b3fbbed403f5 100644 --- a/crates/polars-utils/src/idx_vec.rs +++ b/crates/polars-utils/src/idx_vec.rs @@ -45,10 +45,7 @@ impl UnitVec { #[inline] pub fn new() -> Self { // This is optimized away, all const. - assert!( - std::mem::size_of::() <= std::mem::size_of::<*mut T>() - && std::mem::align_of::() <= std::mem::align_of::<*mut T>() - ); + assert!(size_of::() <= size_of::<*mut T>() && align_of::() <= align_of::<*mut T>()); Self { len: 0, capacity: NonZeroUsize::new(1).unwrap(), diff --git a/crates/polars-utils/src/sort.rs b/crates/polars-utils/src/sort.rs index 780dc39d1b9c..0c83f2becddd 100644 --- a/crates/polars-utils/src/sort.rs +++ b/crates/polars-utils/src/sort.rs @@ -90,8 +90,8 @@ where Idx: FromPrimitive + Copy, { // Needed to be able to write back to back in the same buffer. - debug_assert_eq!(std::mem::align_of::(), std::mem::align_of::<(T, Idx)>()); - let size = std::mem::size_of::<(T, Idx)>(); + debug_assert_eq!(align_of::(), align_of::<(T, Idx)>()); + let size = size_of::<(T, Idx)>(); let upper_bound = size * n + size; scratch.reserve(upper_bound); let scratch_slice = unsafe { diff --git a/crates/polars/tests/it/arrow/compute/aggregate/memory.rs b/crates/polars/tests/it/arrow/compute/aggregate/memory.rs index 075e5179e1ca..942fd38cc4a7 100644 --- a/crates/polars/tests/it/arrow/compute/aggregate/memory.rs +++ b/crates/polars/tests/it/arrow/compute/aggregate/memory.rs @@ -5,7 +5,7 @@ use arrow::datatypes::{ArrowDataType, Field}; #[test] fn primitive() { let a = Int32Array::from_slice([1, 2, 3, 4, 5]); - assert_eq!(5 * std::mem::size_of::(), estimated_bytes_size(&a)); + assert_eq!(5 * size_of::(), estimated_bytes_size(&a)); } #[test] @@ -17,7 +17,7 @@ fn boolean() { #[test] fn utf8() { let a = Utf8Array::::from_slice(["aaa"]); - assert_eq!(3 + 2 * std::mem::size_of::(), estimated_bytes_size(&a)); + assert_eq!(3 + 2 * size_of::(), estimated_bytes_size(&a)); } #[test] @@ -28,5 +28,5 @@ fn fixed_size_list() { ); let values = Box::new(Float32Array::from_slice([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])); let a = FixedSizeListArray::new(dtype, 2, values, None); - assert_eq!(6 * std::mem::size_of::(), estimated_bytes_size(&a)); + assert_eq!(6 * size_of::(), estimated_bytes_size(&a)); } diff --git a/crates/polars/tests/it/io/parquet/read/dictionary/primitive.rs b/crates/polars/tests/it/io/parquet/read/dictionary/primitive.rs index 9b2185656462..188adf8efeba 100644 --- a/crates/polars/tests/it/io/parquet/read/dictionary/primitive.rs +++ b/crates/polars/tests/it/io/parquet/read/dictionary/primitive.rs @@ -30,7 +30,7 @@ pub fn read( num_values: usize, _is_sorted: bool, ) -> ParquetResult> { - let size_of = std::mem::size_of::(); + let size_of = size_of::(); let typed_size = num_values.wrapping_mul(size_of); diff --git a/crates/polars/tests/it/io/parquet/read/primitive_nested.rs b/crates/polars/tests/it/io/parquet/read/primitive_nested.rs index 36fdb254420a..0c3a15922a24 100644 --- a/crates/polars/tests/it/io/parquet/read/primitive_nested.rs +++ b/crates/polars/tests/it/io/parquet/read/primitive_nested.rs @@ -10,7 +10,7 @@ use super::dictionary::PrimitivePageDict; use super::{hybrid_rle_iter, Array}; fn read_buffer(values: &[u8]) -> impl Iterator + '_ { - let chunks = values.chunks_exact(std::mem::size_of::()); + let chunks = values.chunks_exact(size_of::()); chunks.map(|chunk| { // unwrap is infalible due to the chunk size. let chunk: T::Bytes = match chunk.try_into() { diff --git a/crates/polars/tests/it/io/parquet/read/utils.rs b/crates/polars/tests/it/io/parquet/read/utils.rs index 19feaee29534..14b664e0d962 100644 --- a/crates/polars/tests/it/io/parquet/read/utils.rs +++ b/crates/polars/tests/it/io/parquet/read/utils.rs @@ -197,13 +197,11 @@ pub fn native_cast(page: &DataPage) -> ParquetResult> { def: _, values, } = split_buffer(page)?; - if values.len() % std::mem::size_of::() != 0 { + if values.len() % size_of::() != 0 { panic!("A primitive page data's len must be a multiple of the type"); } - Ok(values - .chunks_exact(std::mem::size_of::()) - .map(decode::)) + Ok(values.chunks_exact(size_of::()).map(decode::)) } /// The deserialization state of a `DataPage` of `Primitive` parquet primitive type