-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Make some usize
-typed masks definitions agnostic to the size of usize
#96081
Conversation
Some masks where defined as ```rust const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; ``` where it was assumed that `usize` is never wider than 64, which is currently true. To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an `usize`-width-agnostic way ```rust const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; size_of::<usize>()]); ``` There are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing `From<usize>` for `u64`.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
usize
-typed masks definition agnostic to the size of usize
usize
-typed masks definitions agnostic to the size of usize
Sounds good and looks great, thank you for the PR! @bors r+ |
📌 Commit 93ae6f8 has been approved by |
@@ -77,6 +77,6 @@ fn is_ascii_align_to_unrolled(bytes: &[u8]) -> bool { | |||
|
|||
#[inline] | |||
fn contains_nonascii(v: usize) -> bool { | |||
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; | |||
const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; core::mem::size_of::<usize>()]); |
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.
Why doesn't this use usize::repeat_u8
?
EDIT: Oh, I guess that is crate-private.
Rollup of 7 pull requests Successful merges: - rust-lang#95887 (resolve: Create dummy bindings for all unresolved imports) - rust-lang#96023 (couple of clippy::perf fixes) - rust-lang#96035 (Update GitHub Actions actions/checkout Version v2 -> v3) - rust-lang#96038 (docs: add link from zip to unzip) - rust-lang#96047 (:arrow_up: rust-analyzer) - rust-lang#96059 (clarify doc(cfg) wording) - rust-lang#96081 (Make some `usize`-typed masks definitions agnostic to the size of `usize`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Some masks where defined as
where it was assumed that
usize
is never wider than 64, which is currently true.To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an
usize
-width-agnostic wayThere are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing
From<usize>
foru64
.