From 2830dbd64f50b4a8025025f01578e45cbf9d3719 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 1 May 2022 00:16:16 -0700 Subject: Tweak the calloc optimization to only apply to shortish-arrays --- library/alloc/src/vec/is_zero.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'library/alloc') diff --git a/library/alloc/src/vec/is_zero.rs b/library/alloc/src/vec/is_zero.rs index 868f2f1e323..edf270db81d 100644 --- a/library/alloc/src/vec/is_zero.rs +++ b/library/alloc/src/vec/is_zero.rs @@ -52,7 +52,14 @@ unsafe impl IsZero for *mut T { unsafe impl IsZero for [T; N] { #[inline] fn is_zero(&self) -> bool { - self.iter().all(IsZero::is_zero) + // Because this is generated as a runtime check, it's not obvious that + // it's worth doing if the array is really long. The threshold here + // is largely arbitrary, but was picked because as of 2022-05-01 LLVM + // can const-fold the check in `vec![[0; 32]; n]` but not in + // `vec![[0; 64]; n]`: https://godbolt.org/z/WTzjzfs5b + // Feel free to tweak if you have better evidence. + + N <= 32 && self.iter().all(IsZero::is_zero) } } -- cgit 1.4.1-3-g733a5