-
Notifications
You must be signed in to change notification settings - Fork 13k
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 Vec::clone_from and slice::clone_into share the same code #107424
Conversation
The implementation for the ToOwned::clone_into method on [T] is a copy of the code for vec::clone_from. In 3613980 the code for vec::clone_from gained a specialization for when T is Copy. This commit copies that specialization over to the clone_into implementation.
In the past, Vec::clone_from was implemented using slice::clone_into. The code from clone_into was later duplicated into clone_from in 8725e4c, which is the commit that adds custom allocator support to Vec. Presumably this was done because the slice::clone_into only works for vecs with the default allocator so it would have the wrong type to clone into Vec<T, A>. Now that the clone_into implementation is moved out into a specializable trait anyway we might as well use that to share the code between the two methods.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon. Please see the contribution instructions for more information. |
This comment was marked as resolved.
This comment was marked as resolved.
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.
@bors r+ Thanks for spotting and fixing this! (And sorry for totally missing your note in the PR description about the custom allocators.) |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#107125 (Add and use expect methods to hir.) - rust-lang#107172 (Reimplement NormalizeArrayLen based on SsaLocals) - rust-lang#107177 (Keep all theme-updating logic together) - rust-lang#107424 (Make Vec::clone_from and slice::clone_into share the same code) - rust-lang#107455 (use a more descriptive name) - rust-lang#107465 (`has_allow_dead_code_or_lang_attr` micro refactor) - rust-lang#107469 (Change turbofish context link to an archive link) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
In the past,
Vec::clone_from
was implemented usingslice::clone_into
. The code fromclone_into
was later duplicated intoclone_from
in 8725e4c, which is the commit that adds custom allocator support to Vec. Presumably this was done because theslice::clone_into
method only works for vecs with the default allocator so it would have the wrong type to clone intoVec<T, A>
.Later on in 3613980 the code for the two methods diverged because the
Vec::clone_from
version gained a specialization to optimize the case when T is Copy. In order to reduce code duplication and make them both be able to take advantage of this specialization, this PR moves the specialization into the slice module and makes vec use it again.