-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for making ASCII ctype inherent methods const fn
#68983
Comments
const fn
…=Centril Make ASCII ctype functions unstably const Makes the following inherent methods on `u8` and `char` unstable `const fn`: * `is_ascii_alphabetic` * `is_ascii_uppercase` * `is_ascii_lowercase` * `is_ascii_alphanumeric` * `is_ascii_digit` * `is_ascii_hexdigit` * `is_ascii_punctuation` * `is_ascii_graphic` * `is_ascii_whitespace` * `is_ascii_control` cc rust-lang#68983
Could these be implemented by means of a lookup table? |
@demimarie-parity Sorry I missed your comment. They could be, although the generated code would likely be worse than the branchy version. |
@ecstatic-morse my experience in practice (albeit in Haskell) has been the opposite ― the lookup table is significantly faster. |
You're welcome to try it out. If it is indeed faster, that would be a valuable addition to the standard library. I will point out that the obvious microbenchmark will put the lookup table in the L1 cache, so it won't be fair unless you're calling these functions in a tight loop. Perhaps that's the most common mode of use and we should indeed be optimizing for it? |
My tests were done several years ago, and indeed involved calling these functions in a tight loop. I have no idea if that is the most common use, though. |
I think if you were able to demonstrate that a lookup table based approach was faster in rust in a tight loop, the libs team would seriously consider switching to it. I'm not on the libs team, so I don't know how they evaluate time/memory trade-offs such as this one. If you have any questions about writing microbenchmarks in rust, I'm happy to answer them. If you're not interested, consider opening an issue so someone else can look into it. I think it's an idea that's worth testing. |
Looks like these were already stabilized as const in 1.47. Closing this issue. |
This is a tracking issue for making the inherent methods introduced in #46077 into
const fn
. This includes all functions listed in #39658 for bothu8
andchar
, namely:is_ascii_alphabetic
is_ascii_uppercase
is_ascii_lowercase
is_ascii_alphanumeric
is_ascii_digit
is_ascii_hexdigit
is_ascii_punctuation
is_ascii_graphic
is_ascii_whitespace
is_ascii_control
The feature gate for the const version of these functions is
#![feature(const_ascii_ctype_on_intrinsics)]
. These cannot be const-stabilized until#![feature(const_if_match)]
is stable.The text was updated successfully, but these errors were encountered: