From 37aac8ba966bbace9db0dde77afb49c79a030e28 Mon Sep 17 00:00:00 2001 From: Tzvetan Mikov Date: Thu, 23 Sep 2021 10:10:59 -0700 Subject: [PATCH] EASY: remove unnecessary usage of BufReader Summary: There is no need for BufReader when reading the entire file into a vec. Reviewed By: avp Differential Revision: D31044157 fbshipit-source-id: be692af668afbf3c1b80282035101cbe9fb85dcd --- unsupported/juno/support/src/nullbuf.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/unsupported/juno/support/src/nullbuf.rs b/unsupported/juno/support/src/nullbuf.rs index c2bc990af20..7ee5340cb27 100644 --- a/unsupported/juno/support/src/nullbuf.rs +++ b/unsupported/juno/support/src/nullbuf.rs @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -use std::io::{BufReader, Read}; +use std::io::Read; use std::os::raw::c_char; /// An abstraction for a null-terminated buffer either read from disk, copied @@ -26,7 +26,7 @@ impl NullTerminatedBuf<'_> { /// Create from a reader and null terminate. pub fn from_reader<'a, R: Read>( - reader: &'_ mut R, + mut reader: R, ) -> Result, std::io::Error> { let mut v = Vec::::new(); reader.read_to_end(&mut v)?; @@ -46,8 +46,7 @@ impl NullTerminatedBuf<'_> { // One problem is that there isn't an obvious way in Rust to check portably whether // something has a fixed size and is memory mappable (i.e. is not a pipe). - let mut reader = BufReader::new(f); - Self::from_reader(&mut reader) + Self::from_reader(f) } /// Create by copying a slice and appending null-termination. @@ -115,7 +114,7 @@ impl NullTerminatedBuf<'_> { } } -impl std::convert::AsRef<[u8]> for NullTerminatedBuf<'_> { +impl AsRef<[u8]> for NullTerminatedBuf<'_> { fn as_ref(&self) -> &[u8] { self.as_bytes() }