We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent da9a557 commit 902c7d5Copy full SHA for 902c7d5
alloc/src/vec/is_zero.rs
@@ -52,7 +52,14 @@ unsafe impl<T> IsZero for *mut T {
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)
+ // Because this is generated as a runtime check, it's not obvious that
56
+ // it's worth doing if the array is really long. The threshold here
57
+ // is largely arbitrary, but was picked because as of 2022-05-01 LLVM
58
+ // can const-fold the check in `vec![[0; 32]; n]` but not in
59
+ // `vec![[0; 64]; n]`: https://godbolt.org/z/WTzjzfs5b
60
+ // Feel free to tweak if you have better evidence.
61
+
62
+ N <= 32 && self.iter().all(IsZero::is_zero)
63
}
64
65
0 commit comments