perf: improve Bytes::copy_to_bytes (#688)

Signed-off-by: tison <[email protected]>
This commit is contained in:
tison
2024-04-10 16:45:31 +02:00
committed by GitHub
parent 4eb62b912a
commit b5fbfc3edb
+1 -7
View File
@@ -582,13 +582,7 @@ impl Buf for Bytes {
}
fn copy_to_bytes(&mut self, len: usize) -> Self {
if len == self.remaining() {
core::mem::replace(self, Bytes::new())
} else {
let ret = self.slice(..len);
self.advance(len);
ret
}
self.split_to(len)
}
}