mirror of
https://github.com/openharmony/third_party_rust_tinyvec.git
synced 2026-07-19 14:23:33 -04:00
Switch to slice swapping for split
The new slice is already initialized with default values for T due to the constructor used. Instead of using different defaulted values for replacing the split-off instances we can simply swap slices. This reduces pressure on the optimizer and uses a probably optimized method from the core library.
This commit is contained in:
+4
-5
@@ -544,11 +544,10 @@ impl<A: Array> ArrayVec<A> {
|
||||
}
|
||||
let mut new = Self::default();
|
||||
let moves = &mut self.as_mut_slice()[at..];
|
||||
let targets = new.data.as_slice_mut();
|
||||
for (m, t) in moves.iter_mut().zip(targets) {
|
||||
replace(t, replace(m, A::Item::default()));
|
||||
}
|
||||
new.len = self.len - at;
|
||||
let split_len = moves.len();
|
||||
let targets = &mut new.data.as_slice_mut()[..split_len];
|
||||
moves.swap_with_slice(targets);
|
||||
new.len = split_len;
|
||||
self.len = at;
|
||||
new
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user