Skip to content
Draft
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/uu/shuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ path = "src/shuf.rs"

[dependencies]
clap = { workspace = true }
fluent = { workspace = true }
itoa = { workspace = true }
memchr = { workspace = true }
rand = { workspace = true }
rand_chacha = { workspace = true }
rustc-hash = { workspace = true }
sha3 = { workspace = true }
uucore = { workspace = true }
fluent = { workspace = true }
rustc-hash = { workspace = true }

[[bin]]
name = "shuf"
Expand Down
8 changes: 4 additions & 4 deletions src/uu/shuf/src/shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use clap::{Arg, ArgAction, Command, builder::ValueParser};
use memchr::memchr_iter;
use rand::{
RngExt as _,
rngs::ThreadRng,
Expand Down Expand Up @@ -267,14 +268,13 @@ fn read_input_file(filename: &Path) -> UResult<Vec<u8>> {
}
}

fn split_seps(data: &[u8], sep: u8) -> Vec<&[u8]> {
pub fn split_seps(data: &[u8], sep: u8) -> Vec<&[u8]> {
// A single trailing separator is ignored.
// If data is empty (and does not even contain a single 'sep'
// to indicate the presence of an empty element), then behave
// as if the input contained no elements at all.
const PREDICTED_LINE_LENGTH: usize = 64;
let predicted_capacity = data.len() / PREDICTED_LINE_LENGTH;
let mut elements = Vec::with_capacity(predicted_capacity);
let sep_count = memchr_iter(sep, data).count();
let mut elements = Vec::with_capacity(sep_count + 1);
elements.extend(data.split(|&b| b == sep));
let _ = elements.pop_if(|e| e.is_empty());
elements
Expand Down
Loading