fix: use split_off to take n

This commit is contained in:
leeeon233 2023-03-06 14:52:30 +08:00
parent 3a0b8d9d58
commit 6fd81c8d20

View file

@ -440,7 +440,9 @@ impl<T: Clone + PartialEq + Debug> DeltaValue for Vec<T> {
}
fn take(&mut self, length: usize) -> Self {
self.drain(0..length).collect()
let mut new = self.split_off(length);
std::mem::swap(self, &mut new);
new
}
}
@ -450,7 +452,9 @@ impl DeltaValue for String {
}
fn take(&mut self, length: usize) -> Self {
self.drain(0..length).collect()
let mut new = self.split_off(length);
std::mem::swap(self, &mut new);
new
}
}