Auto merge of #95362 - scottmcm:calloc-arrays, r=Mark-Simulacrum

Support arrays of zeros in Vec's __rust_alloc_zeroed optimization

I happened to notice in https://users.rust-lang.org/t/any-advantage-of-box-u64-16-16-16-over-vec-u64/73500/3?u=scottmcm that the calloc optimization wasn't applying to vectors-of-arrays, so here's the easy fix for that.
This commit is contained in:
bors 2022-05-01 00:50:46 +00:00
commit bf611439e3

View File

@ -2,7 +2,7 @@
#[rustc_specialization_trait]
pub(super) unsafe trait IsZero {
/// Whether this value is zero
/// Whether this value's representation is all zeros
fn is_zero(&self) -> bool;
}
@ -49,6 +49,13 @@ fn is_zero(&self) -> bool {
}
}
unsafe impl<T: IsZero, const N: usize> IsZero for [T; N] {
#[inline]
fn is_zero(&self) -> bool {
self.iter().all(IsZero::is_zero)
}
}
// `Option<&T>` and `Option<Box<T>>` are guaranteed to represent `None` as null.
// For fat pointers, the bytes that would be the pointer metadata in the `Some`
// variant are padding in the `None` variant, so ignoring them and