Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/uu/wc/src/countable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use std::io::{BufRead, BufReader, Read, StdinLock};
#[cfg(unix)]
use std::os::fd::{AsFd, AsRawFd};

const WORD_COUNT_BUF_SIZE: usize = 256 * 1024;

#[cfg(unix)]
pub trait WordCountable: AsFd + AsRawFd + Read {
type Buffered: BufRead;
Expand All @@ -28,10 +30,10 @@ pub trait WordCountable: Read {
}

impl WordCountable for StdinLock<'_> {
type Buffered = Self;
type Buffered = BufReader<Self>;

fn buffered(self) -> Self::Buffered {
self
BufReader::with_capacity(WORD_COUNT_BUF_SIZE, self)
}
fn inner_file(&mut self) -> Option<&mut File> {
None
Expand All @@ -42,7 +44,7 @@ impl WordCountable for File {
type Buffered = BufReader<Self>;

fn buffered(self) -> Self::Buffered {
BufReader::new(self)
BufReader::with_capacity(WORD_COUNT_BUF_SIZE, self)
}

fn inner_file(&mut self) -> Option<&mut File> {
Expand Down
Loading