Skip to content

Commit b50eadf

Browse files
committed
wc: use memchr crate for line counting
1 parent 6130076 commit b50eadf

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/wc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ doctest = false
2323
bytecount = { workspace = true, features = ["runtime-dispatch-simd"] }
2424
clap = { workspace = true }
2525
fluent = { workspace = true }
26+
memchr = { workspace = true }
2627
thiserror = { workspace = true }
2728
uucore = { workspace = true, features = [
2829
"hardware",

src/uu/wc/src/count_fast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// cSpell:ignore sysconf
77
use crate::{wc_simd_allowed, word_count::WordCount};
8+
use memchr::memchr_iter;
89
use uucore::hardware::SimdPolicy;
910

1011
use super::WordCountable;
@@ -238,9 +239,9 @@ pub(crate) fn count_bytes_chars_and_lines_fast<
238239
}
239240
if COUNT_LINES {
240241
total.lines += if simd_allowed {
241-
bytecount::count(&buf[..n], b'\n')
242+
memchr_iter(b'\n', &buf[..n]).count()
242243
} else {
243-
bytecount::naive_count(&buf[..n], b'\n')
244+
buf[..n].iter().filter(|&&c| c == b'\n').count()
244245
};
245246
}
246247
}

0 commit comments

Comments
 (0)