-
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
Use unchecked_sub
in split_at
#124699
Use unchecked_sub
in split_at
#124699
Conversation
@@ -2035,7 +2035,12 @@ impl<T> [T] { | |||
// | |||
// `[ptr; mid]` and `[mid; len]` are not overlapping, so returning a mutable reference | |||
// is fine. | |||
unsafe { (from_raw_parts_mut(ptr, mid), from_raw_parts_mut(ptr.add(mid), len - mid)) } | |||
unsafe { |
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.
two local variables for the left and right sides would have been nice here to reduce the lines from 6 to 3 :3, things like this are certainly formative of your opinions about rustfmt 😆 (though i can't really complain, it's doing its best)
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.
Yeah, my preferred philosophical underpinnings for a formatter are pretty different from those that rustfmt picked :(
@bors r+ rollup |
r? Nilstrieb |
…_use_unchecked, r=Nilstrieb Use `unchecked_sub` in `split_at` LLVM currently isn't figuring it out on its own, even in the checked version where it hypothetically could. Before: <https://rust.godbolt.org/z/PEY38YrKs> ```llvm bb1: ; preds = %start %4 = getelementptr inbounds float, ptr %x.0, i64 %n %5 = sub i64 %x.1, %n ``` After: ```llvm bb1: ; preds = %start %4 = getelementptr inbounds float, ptr %x.0, i64 %n %5 = sub nuw i64 %x.1, %n ``` This is not using the wrapper because there's already a ubcheck covering it, so I don't want this to get a second one once rust-lang#121571 lands. --- This is basically the same as rust-lang#108763, since `split_at` is essentially doing two `get_unchecked`s.
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#122441 (Improve several `Read` implementations) - rust-lang#124584 (Various improvements to entrypoint code) - rust-lang#124699 (Use `unchecked_sub` in `split_at`) - rust-lang#124704 (Fix ignored tests for formatting) - rust-lang#124709 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#122441 (Improve several `Read` implementations) - rust-lang#124584 (Various improvements to entrypoint code) - rust-lang#124699 (Use `unchecked_sub` in `split_at`) - rust-lang#124704 (Fix ignored tests for formatting) - rust-lang#124709 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#122441 (Improve several `Read` implementations) - rust-lang#124584 (Various improvements to entrypoint code) - rust-lang#124699 (Use `unchecked_sub` in `split_at`) - rust-lang#124715 (interpret, miri: uniform treatments of intrinsics/functions with and without return block) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124699 - scottmcm:split_at_unchecked_should_use_unchecked, r=Nilstrieb Use `unchecked_sub` in `split_at` LLVM currently isn't figuring it out on its own, even in the checked version where it hypothetically could. Before: <https://rust.godbolt.org/z/PEY38YrKs> ```llvm bb1: ; preds = %start %4 = getelementptr inbounds float, ptr %x.0, i64 %n %5 = sub i64 %x.1, %n ``` After: ```llvm bb1: ; preds = %start %4 = getelementptr inbounds float, ptr %x.0, i64 %n %5 = sub nuw i64 %x.1, %n ``` This is not using the wrapper because there's already a ubcheck covering it, so I don't want this to get a second one once rust-lang#121571 lands. --- This is basically the same as rust-lang#108763, since `split_at` is essentially doing two `get_unchecked`s.
LLVM currently isn't figuring it out on its own, even in the checked version where it hypothetically could.
Before: https://rust.godbolt.org/z/PEY38YrKs
After:
This is not using the wrapper because there's already a ubcheck covering it, so I don't want this to get a second one once #121571 lands.
This is basically the same as #108763, since
split_at
is essentially doing twoget_unchecked
s.