-
Notifications
You must be signed in to change notification settings - Fork 13.6k
str: Mark unstable round_char_boundary
feature functions as const
#144472
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
Conversation
rustbot has assigned @Mark-Simulacrum. Use |
I wouldn't necessarily say this "simplifies" the implementation since a lot of this is relative to what the optimised output is, and the new implementation may not be as clear to the optimizer that at most four iterations happen. However, I think that it's a valid implementation and making it const is nice. |
} | ||
|
||
// The character boundary will be within four bytes of the index | ||
debug_assert!(i <= index + 3); |
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.
Personally, I think that simply adding this as a condition to the loop itself might be helpful (and similarly above) to ensure that the optimiser knows this precondition as well. Not sure how it'd affect codegen, but it feels like the safest approach compared to, for example, assert_unchecked
.
Compiler explorer links Some surface notes: I filed an issue because of noticing something in the original implementation #139759. |
Mark `floor_char_boundary`, `ceil_char_boundary` const Simplify the implementations, reducing the number of arithmetic operations
@bors r+ Seems reasonable enough and ~equally clear to me. |
Rollup of 7 pull requests Successful merges: - #144072 (update `Atomic*::from_ptr` and `Atomic*::as_ptr` docs) - #144151 (`tests/ui/issues/`: The Issues Strike Back [1/N]) - #144300 (Clippy fixes for miropt-test-tools) - #144399 (Add a ratchet for moving all standard library tests to separate packages) - #144472 (str: Mark unstable `round_char_boundary` feature functions as const) - #144503 (Various refactors to the codegen coordinator code (part 3)) - #144530 (coverage: Infer `instances_used` from `pgo_func_name_var_map`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #144472 - okaneco:char_bound, r=Mark-Simulacrum str: Mark unstable `round_char_boundary` feature functions as const Mark `floor_char_boundary`, `ceil_char_boundary` const Simplify the implementations, reducing the number of arithmetic operations It seems unnecessary to do the lower/upper bounds calculations and extra slicing when we can jump straight to inspecting the bytes, assuming the underlying data is valid UTF-8. Tracking issue #93743
str: Mark unstable `round_char_boundary` feature functions as const Mark `floor_char_boundary`, `ceil_char_boundary` const Simplify the implementations, reducing the number of arithmetic operations It seems unnecessary to do the lower/upper bounds calculations and extra slicing when we can jump straight to inspecting the bytes, assuming the underlying data is valid UTF-8. Tracking issue rust-lang#93743
Mark
floor_char_boundary
,ceil_char_boundary
constSimplify the implementations, reducing the number of arithmetic operations
It seems unnecessary to do the lower/upper bounds calculations and extra slicing when we can jump straight to inspecting the bytes, assuming the underlying data is valid UTF-8.
Tracking issue #93743