mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
perf: improve Bytes::copy_to_bytes (#688)
Signed-off-by: tison <[email protected]>
This commit is contained in:
+1
-7
@@ -582,13 +582,7 @@ impl Buf for Bytes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn copy_to_bytes(&mut self, len: usize) -> Self {
|
fn copy_to_bytes(&mut self, len: usize) -> Self {
|
||||||
if len == self.remaining() {
|
self.split_to(len)
|
||||||
core::mem::replace(self, Bytes::new())
|
|
||||||
} else {
|
|
||||||
let ret = self.slice(..len);
|
|
||||||
self.advance(len);
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user