mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Support arrays of zeros in Vec's __rust_alloc_zeroed optimization
This commit is contained in:
parent
185a3f0a11
commit
8034c45a07
@ -2,7 +2,7 @@ use crate::boxed::Box;
|
||||
|
||||
#[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 @@ unsafe impl<T> IsZero for *mut T {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user