From 61c6eafc089d03a028cfdef9b59e4be8fb1529c2 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 14 Oct 2020 14:10:28 +0200 Subject: [PATCH] AsyncIndexReader: avoid memcpy, add clippy lint fixup comment Signed-off-by: Wolfgang Bumiller --- src/backup/async_index_reader.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/backup/async_index_reader.rs b/src/backup/async_index_reader.rs index 98372aa1..f6a72099 100644 --- a/src/backup/async_index_reader.rs +++ b/src/backup/async_index_reader.rs @@ -15,6 +15,17 @@ use super::IndexFile; use super::read_chunk::AsyncReadChunk; use super::index::ChunkReadInfo; +// FIXME: This enum may not be required? +// - Put the `WaitForData` case directly into a `read_future: Option<>` +// - make the read loop as follows: +// * if read_buffer is not empty: +// use it +// * else if read_future is there: +// poll it +// if read: move data to read_buffer +// * else +// create read future +#[allow(clippy::enum_variant_names)] enum AsyncIndexReaderState { NoData, WaitForData(Pin), Error>> + Send + 'static>>), @@ -118,9 +129,8 @@ where } AsyncIndexReaderState::WaitForData(ref mut future) => { match ready!(future.as_mut().poll(cx)) { - Ok((store, mut chunk_data)) => { - this.read_buffer.clear(); - this.read_buffer.append(&mut chunk_data); + Ok((store, chunk_data)) => { + this.read_buffer = chunk_data; this.state = AsyncIndexReaderState::HaveData; this.store = Some(store); }