Skip to content

Commit bf61143

Browse files
committed
Auto merge of rust-lang#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.
2 parents 2c858a7 + 8034c45 commit bf61143

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

library/alloc/src/vec/is_zero.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::boxed::Box;
22

33
#[rustc_specialization_trait]
44
pub(super) unsafe trait IsZero {
5-
/// Whether this value is zero
5+
/// Whether this value's representation is all zeros
66
fn is_zero(&self) -> bool;
77
}
88

@@ -49,6 +49,13 @@ unsafe impl<T> IsZero for *mut T {
4949
}
5050
}
5151

52+
unsafe impl<T: IsZero, const N: usize> IsZero for [T; N] {
53+
#[inline]
54+
fn is_zero(&self) -> bool {
55+
self.iter().all(IsZero::is_zero)
56+
}
57+
}
58+
5259
// `Option<&T>` and `Option<Box<T>>` are guaranteed to represent `None` as null.
5360
// For fat pointers, the bytes that would be the pointer metadata in the `Some`
5461
// variant are padding in the `None` variant, so ignoring them and

0 commit comments

Comments
 (0)