-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
prefer T::IS_ZST over manual check
#155840
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,8 @@ | |
| // Note that ERMSB does not enhance the backwards (DF=1) "rep movsb". | ||
|
|
||
| use core::arch::asm; | ||
| use core::{intrinsics, mem}; | ||
| use core::intrinsics; | ||
| use core::mem::{self, SizedTypeProperties}; | ||
|
|
||
| #[inline(always)] | ||
| #[cfg(target_feature = "ermsb")] | ||
|
|
@@ -135,7 +136,7 @@ pub unsafe fn compare_bytes(a: *const u8, b: *const u8, n: usize) -> i32 { | |
| F: FnOnce(*const U, *const U, usize) -> i32, | ||
| { | ||
| // Ensure T is not a ZST. | ||
| const { assert!(mem::size_of::<T>() != 0) }; | ||
| const { assert!(!T::IS_ZST) }; | ||
|
Comment on lines
137
to
+139
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for this change? The top post says clearer intent and possible perf improvement, but it has a comment and it's in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to assure T is not a ZST, |
||
|
|
||
| let end = a.add(intrinsics::unchecked_div(n, mem::size_of::<T>())); | ||
| while a != end { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than enabling this whole feature, would it be better for the compiler to have it's own
IsZsttrait specifically forIS_ZST?View changes since the review
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sized_type_propertiesis a pretty small feature, it only gates theSizedTypePropertiestrait which does nothing but define a few constants. I don't know what rustc's policy on avoiding unstable features is, if it is an issue I'm happy to make such a trait.