1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #7400 from cakebaker/mktemp_tr_use_repeat_n

mktemp,tr: replace `repeat().take()` with `repeat_n()`
This commit is contained in:
Sylvestre Ledru 2025-03-04 16:06:09 +01:00 committed by GitHub
commit cda24c678a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 6 deletions

View file

@ -424,9 +424,7 @@ fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult<P
let len = prefix.len() + suffix.len() + rand;
let mut buf = Vec::with_capacity(len);
buf.extend(prefix.as_bytes());
// In Rust v1.82.0, use `repeat_n`:
// <https://doc.rust-lang.org/std/iter/fn.repeat_n.html>
buf.extend(iter::repeat(b'X').take(rand));
buf.extend(iter::repeat_n(b'X', rand));
buf.extend(suffix.as_bytes());
// Randomize.

View file

@ -132,9 +132,7 @@ impl Sequence {
Self::Char(c) => Box::new(std::iter::once(*c)),
Self::CharRange(l, r) => Box::new(*l..=*r),
Self::CharStar(c) => Box::new(std::iter::repeat(*c)),
// In Rust v1.82.0, use `repeat_n`:
// <https://doc.rust-lang.org/std/iter/fn.repeat_n.html>
Self::CharRepeat(c, n) => Box::new(std::iter::repeat(*c).take(*n)),
Self::CharRepeat(c, n) => Box::new(std::iter::repeat_n(*c, *n)),
Self::Class(class) => match class {
Class::Alnum => Box::new((b'0'..=b'9').chain(b'A'..=b'Z').chain(b'a'..=b'z')),
Class::Alpha => Box::new((b'A'..=b'Z').chain(b'a'..=b'z')),