mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 03:44:24 +00:00
Use split_at in slice's ToOwned::clone_into
It appears to codegen slightly more efficiently with `split_at` taking two slices at once, rather than slicing across different calls.
This commit is contained in:
parent
6dee5f1126
commit
e8339e820b
@ -733,14 +733,14 @@ impl<T: Clone> ToOwned for [T] {
|
||||
fn clone_into(&self, target: &mut Vec<T>) {
|
||||
// drop anything in target that will not be overwritten
|
||||
target.truncate(self.len());
|
||||
let len = target.len();
|
||||
|
||||
// reuse the contained values' allocations/resources.
|
||||
target.clone_from_slice(&self[..len]);
|
||||
|
||||
// target.len <= self.len due to the truncate above, so the
|
||||
// slice here is always in-bounds.
|
||||
target.extend_from_slice(&self[len..]);
|
||||
// slices here are always in-bounds.
|
||||
let (init, tail) = self.split_at(target.len());
|
||||
|
||||
// reuse the contained values' allocations/resources.
|
||||
target.clone_from_slice(init);
|
||||
target.extend_from_slice(tail);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user