Skip to content
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

Optimize ptr::replace #122601

Merged
merged 1 commit into from
Mar 17, 2024
Merged

Optimize ptr::replace #122601

merged 1 commit into from
Mar 17, 2024

Conversation

joboet
Copy link
Member

@joboet joboet commented Mar 16, 2024

#83022 optimized mem::replace to reduce the number of memcpys. ptr::replace, which is documented to behave just like mem::replace, was not optimized however, leading to worse code and missed optimizations. This PR simply forwards ptr::replace to mem::replace to take advantage of the better implementation.

@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2024

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 16, 2024
@workingjubilee
Copy link
Member

@joboet Do you expect running perf to be useful?

@joboet
Copy link
Member Author

joboet commented Mar 16, 2024

I don't really think so, most places will use mem::replace directly.

@workingjubilee
Copy link
Member

Yeah, that's what I expect too.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 16, 2024

📌 Commit f272133 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 17, 2024
Rollup of 9 pull requests

Successful merges:

 - rust-lang#117918 (Add `wasm_c_abi` `future-incompat` lint)
 - rust-lang#121545 (fix attribute validation on associated items in traits)
 - rust-lang#121720 (Split refining_impl_trait lint into _reachable, _internal variants)
 - rust-lang#122270 (fix `long-linker-command-lines` failure caused by `rust.rpath=false`)
 - rust-lang#122564 (Delegation: fix ICE on duplicated associative items)
 - rust-lang#122577 (Remove obsolete parameter `speculative` from `instantiate_poly_trait_ref`)
 - rust-lang#122601 (Optimize `ptr::replace`)
 - rust-lang#122604 (Mention jieyouxu for changes to compiletest, run-make tests and the run-make-support library)
 - rust-lang#122605 (rustc-metadata: Store crate name in self-profile of metadata_register_crate)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit de0c2a4 into rust-lang:master Mar 17, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 17, 2024
Rollup merge of rust-lang#122601 - joboet:ptr_replace, r=workingjubilee

Optimize `ptr::replace`

rust-lang#83022 optimized `mem::replace` to reduce the number of `memcpy`s. `ptr::replace`, which is [documented to behave just like `mem::replace`](https://doc.rust-lang.org/nightly/std/ptr/fn.replace.html), was not optimized however, leading to [worse code](https://godbolt.org/z/T3hdEEdfe) and missed optimizations. This PR simply forwards `ptr::replace` to `mem::replace` to take advantage of the better implementation.
@cuviper cuviper modified the milestones: 1.78.0, 1.79.0 Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants