Skip to content

Commit

Permalink
EASY: remove unnecessary usage of BufReader
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tmikov authored and facebook-github-bot committed Sep 23, 2021
1 parent e39e170 commit 37aac8b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions unsupported/juno/support/src/nullbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<NullTerminatedBuf<'a>, std::io::Error> {
let mut v = Vec::<u8>::new();
reader.read_to_end(&mut v)?;
Expand All @@ -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.
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 37aac8b

Please sign in to comment.