diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-03-27 01:03:10 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-03-27 01:50:07 -0700 |
| commit | 8034c45a07ff782b32f3fdc054338b524847aea1 (patch) | |
| tree | 91492975c35dc3517f24385eb8128dbe871ee32d /library/alloc/src/vec | |
| parent | 185a3f0a112fd6439247cf15452d0c5dfb3c8c92 (diff) | |
| download | rust-8034c45a07ff782b32f3fdc054338b524847aea1.tar.gz rust-8034c45a07ff782b32f3fdc054338b524847aea1.zip | |
Support arrays of zeros in Vec's __rust_alloc_zeroed optimization
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/is_zero.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/library/alloc/src/vec/is_zero.rs b/library/alloc/src/vec/is_zero.rs index 0efc4893c3c..868f2f1e323 100644 --- a/library/alloc/src/vec/is_zero.rs +++ b/library/alloc/src/vec/is_zero.rs @@ -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 |
