Skip to content

Commit

Permalink
chore: avoid allocation when generating temp names
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jan 8, 2022
1 parent f83a062 commit e24fae3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/util.rs
Expand Up @@ -8,11 +8,10 @@ use crate::error::IoResultExt;
fn tmpname(prefix: &OsStr, suffix: &OsStr, rand_len: usize) -> OsString {
let mut buf = OsString::with_capacity(prefix.len() + suffix.len() + rand_len);
buf.push(prefix);
buf.push(
repeat_with(fastrand::alphanumeric)
.take(rand_len)
.collect::<String>(),
);
let mut char_buf = [0u8; 4];
for c in repeat_with(fastrand::alphanumeric).take(rand_len) {
buf.push(c.encode_utf8(&mut char_buf));
}
buf.push(suffix);
buf
}
Expand Down

0 comments on commit e24fae3

Please sign in to comment.