]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #107424 - bpeel:clone-into-from-share-code, r=scottmcm
authorMatthias Krüger <matthias.krueger@famsik.de>
Mon, 30 Jan 2023 16:50:10 +0000 (17:50 +0100)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 16:50:10 +0000 (17:50 +0100)
commitb3b9383f8d1324ca2fd34a34cdd026ba40c2e935
tree7dae9c877d82bd85cdd6278693ce7581e67fad7a
parentd1320a542f0b27e060d19a87571e2e499b2d304a
parenta34f11c006936f0935c0f3484f9a292901d0eade
Rollup merge of #107424 - bpeel:clone-into-from-share-code, r=scottmcm

Make Vec::clone_from and slice::clone_into share the same code

In the past, `Vec::clone_from` was implemented using `slice::clone_into`. The code from `clone_into` was later duplicated into `clone_from` in 8725e4c337, which is the commit that adds custom allocator support to Vec. Presumably this was done because the `slice::clone_into` method only works for vecs with the default allocator so it would have the wrong type to clone into `Vec<T, A>`.

Later on in 361398009be6 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.