Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/uu/wc/BENCHMARKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ output of uutils `cat` into it. Note that GNU `cat` is slower and therefore less
suitable, and that if a file is given as its input directly (as in
`wc -c < largefile`) the first strategy kicks in. Try `uucat somefile | wc -c`.

### Counting lines
### Counting lines and UTF-8 characters

In the case of `wc -l` or `wc -cl` the input doesn't have to be decoded. It's
read in chunks and the `bytecount` crate is used to count the newlines.
If the flags set are a subset of `-clm` then the input doesn't have to be decoded. The
input is read in chunks and the `bytecount` crate is used to count the newlines (`-l` flag)
and/or UTF-8 characters (`-m` flag).

It's useful to vary the line length in the input. GNU wc seems particularly
bad at short lines.
Expand Down
2 changes: 1 addition & 1 deletion src/uu/wc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "src/wc.rs"
[dependencies]
clap = { workspace = true }
uucore = { workspace = true, features = ["pipes", "quoting-style"] }
bytecount = { workspace = true }
bytecount = { workspace = true, features = ["runtime-dispatch-simd"] }
thiserror = { workspace = true }
unicode-width = { workspace = true }

Expand Down
10 changes: 1 addition & 9 deletions src/uu/wc/src/count_fast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ pub(crate) fn count_bytes_chars_and_lines_fast<
>(
handle: &mut R,
) -> (WordCount, Option<io::Error>) {
/// Mask of the value bits of a continuation byte
const CONT_MASK: u8 = 0b0011_1111u8;
/// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte
const TAG_CONT_U8: u8 = 0b1000_0000u8;

let mut total = WordCount::default();
let mut buf = [0; BUF_SIZE];
loop {
Expand All @@ -227,10 +222,7 @@ pub(crate) fn count_bytes_chars_and_lines_fast<
total.bytes += n;
}
if COUNT_CHARS {
total.chars += buf[..n]
.iter()
.filter(|&&byte| (byte & !CONT_MASK) != TAG_CONT_U8)
.count();
total.chars += bytecount::num_chars(&buf[..n]);
}
if COUNT_LINES {
total.lines += bytecount::count(&buf[..n], b'\n');
Expand Down
Loading