mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-05 02:18:16 +00:00
ByteBuffer: skip the temporary Vec
The docs say `into_boxed_slice()` "drops" excess capacity, but doesn't specify whether that just means it becomes inaccessible or the vector potentially reallocates to the exact size. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
f8ea74dfc1
commit
816015ed01
@ -131,11 +131,10 @@ impl ByteBuffer {
|
||||
/// ```
|
||||
pub fn consume(&mut self, max_amount: usize) -> Box<[u8]> {
|
||||
let size = min(max_amount, self.data_size);
|
||||
let mut tmp = Vec::with_capacity(size);
|
||||
tmp.extend_from_slice(&self.buf[..size]);
|
||||
let tmp: Box<[u8]> = self.buf[..size].into();
|
||||
self.buf.copy_within(size..self.capacity, 0);
|
||||
self.data_size -= size;
|
||||
tmp.into_boxed_slice()
|
||||
tmp
|
||||
}
|
||||
|
||||
/// Takes a reader and reads into the back of the buffer (up to the
|
||||
|
Loading…
Reference in New Issue
Block a user