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:
Andreas Molzer
2020-01-18 16:05:13 +01:00
parent ff7eaa0f8a
commit eed51be53b
+4 -5
View File
@@ -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
}