chore: reduce allocations in a few places (#27288)

Probably doesn't have much impact. I didn't measure any of these, but
reducing allocations should always be good.
This commit is contained in:
David Sherret 2024-12-09 19:28:53 -05:00 committed by Bartek Iwańczuk
parent d410358789
commit c402448061
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
7 changed files with 54 additions and 26 deletions

View file

@ -219,8 +219,9 @@ fn get_atomic_dir_path(file_path: &Path) -> PathBuf {
}
fn gen_rand_path_component() -> String {
(0..4).fold(String::new(), |mut output, _| {
output.push_str(&format!("{:02x}", rand::random::<u8>()));
use std::fmt::Write;
(0..4).fold(String::with_capacity(8), |mut output, _| {
write!(&mut output, "{:02x}", rand::random::<u8>()).unwrap();
output
})
}