From 9209b822a9cb3017088d16de32d135caa5508e64 Mon Sep 17 00:00:00 2001 From: Edward Shen Date: Wed, 14 Jul 2021 14:20:31 -0400 Subject: [PATCH] Simplify DiskWriter poll_flush --- src/cache/fs.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/cache/fs.rs b/src/cache/fs.rs index ec5e941..5970637 100644 --- a/src/cache/fs.rs +++ b/src/cache/fs.rs @@ -331,26 +331,20 @@ impl AsyncWrite for EncryptedDiskWriter { } #[inline] - fn poll_flush( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> { - if self.buffer.is_empty() { - self.as_mut().file.as_mut().poll_flush(cx) - } else { - let pinned = Pin::into_inner(self); - while !pinned.buffer.is_empty() { - match pinned.file.as_mut().poll_write(cx, &pinned.buffer) { - Poll::Ready(Ok(n)) => { - pinned.buffer.drain(..n); - } - Poll::Ready(Err(e)) => return Poll::Ready(Err(e)), - Poll::Pending => return Poll::Pending, - } - } + fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + let pinned = Pin::into_inner(self); - Poll::Ready(Ok(())) + while !pinned.buffer.is_empty() { + match pinned.file.as_mut().poll_write(cx, &pinned.buffer) { + Poll::Ready(Ok(n)) => { + pinned.buffer.drain(..n); + } + Poll::Ready(Err(e)) => return Poll::Ready(Err(e)), + Poll::Pending => return Poll::Pending, + } } + + pinned.file.as_mut().poll_flush(cx) } #[inline]