From 6fd81c8d20ff170760fa6dd3dd34631763e8cd99 Mon Sep 17 00:00:00 2001 From: leeeon233 Date: Mon, 6 Mar 2023 14:52:30 +0800 Subject: [PATCH] fix: use split_off to take n --- crates/loro-internal/src/delta/seq.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/loro-internal/src/delta/seq.rs b/crates/loro-internal/src/delta/seq.rs index 70469f4b..78744bd1 100644 --- a/crates/loro-internal/src/delta/seq.rs +++ b/crates/loro-internal/src/delta/seq.rs @@ -440,7 +440,9 @@ impl DeltaValue for Vec { } 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 } }