-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement IzZero for zeroable default types #60978
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
A-collections
Area: `std::collections`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
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 |
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Sep 4, 2022
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
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
A-collections
Area: `std::collections`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
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: