From 3f5d0985f04b3af26dd37f9cc3c74a44dd0dbfcf Mon Sep 17 00:00:00 2001 From: PhotonQuantum Date: Fri, 15 Oct 2021 07:12:53 +0800 Subject: [PATCH] Move ReadBuffer chunk to heap --- src/buffer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index c080fdb..a5e7490 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -12,7 +12,7 @@ use bytes::Buf; #[derive(Debug)] pub struct ReadBuffer { storage: Cursor>, - chunk: [u8; CHUNK_SIZE], + chunk: Box<[u8; CHUNK_SIZE]>, } impl ReadBuffer { @@ -28,7 +28,7 @@ impl ReadBuffer { /// Create a input buffer filled with previously read data. pub fn from_partially_read(part: Vec) -> Self { - Self { storage: Cursor::new(part), chunk: [0; CHUNK_SIZE] } + Self { storage: Cursor::new(part), chunk: Box::new([0; CHUNK_SIZE]) } } /// Get a cursor to the data storage. @@ -54,7 +54,7 @@ impl ReadBuffer { /// Read next portion of data from the given input stream. pub fn read_from(&mut self, stream: &mut S) -> IoResult { self.clean_up(); - let size = stream.read(&mut self.chunk)?; + let size = stream.read(&mut *self.chunk)?; self.storage.get_mut().extend_from_slice(&self.chunk[..size]); Ok(size) }