-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement IzZero for zeroable default types #60978
Comments
That trait is only used by internal Windows things. It probably does not have the semantics you're looking for. |
Ah, did you mean to link this trait instead? Lines 1594 to 1597 in 372be4f
|
@jonas-schievink yes, I linked the wrong trait, fixed. Thanks. |
Is |
let foo : Option<bool> = Option::None;
println!("size:{} val:{:08b}",
std::mem::size_of::<Option<bool>>(),
unsafe {std::mem::transmute::<Option<bool>, u8>(foo)});
// size:1 val:00000010 |
Implement internal `IsZero` for Wrapping and Saturating for `Vec` optimizations This implements the `IsZero` trait for the `Wrapping` and `Saturating` types so that users of these types can get the improved performance from the specialization of creating a `Vec` from a single element repeated when it has a zero bit pattern (example `vec![0_i32; 500]`, or after this PR `vec![Wrapping(0_i32); 500]`) CC rust-lang#60978
As discussed in #54628 there are some critical optimizations based on fact that type default value can be represented with
mem::zeroed()
, such as this vec allocation code.There is a trait describing this behavior. I propose implementing it for some standard types, such as
std::num::Wrapping
orOption
, or even making it public.The text was updated successfully, but these errors were encountered: